repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
jhalterman/sarge
src/main/java/net/jodah/sarge/internal/SupervisionRegistry.java
// Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/Supervisor.java // public interface Supervisor { // /** Returns the plan to be used when supervising child objects. */ // Plan plan(); // }
import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import net.jodah.sarge.Plan; import net.jodah.sarge.Supervisor;
package net.jodah.sarge.internal; /** * Statically stores and retrieves SupervisionContext instances. * * @author Jonathan Halterman */ public class SupervisionRegistry { private final Map<Object, Supervisor> supervisors = new ConcurrentHashMap<Object, Supervisor>();
// Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/Supervisor.java // public interface Supervisor { // /** Returns the plan to be used when supervising child objects. */ // Plan plan(); // } // Path: src/main/java/net/jodah/sarge/internal/SupervisionRegistry.java import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import net.jodah.sarge.Plan; import net.jodah.sarge.Supervisor; package net.jodah.sarge.internal; /** * Statically stores and retrieves SupervisionContext instances. * * @author Jonathan Halterman */ public class SupervisionRegistry { private final Map<Object, Supervisor> supervisors = new ConcurrentHashMap<Object, Supervisor>();
private final Map<Object, Plan> plans = new ConcurrentHashMap<Object, Plan>();
jhalterman/sarge
src/main/java/net/jodah/sarge/PlanMaker.java
// Path: src/main/java/net/jodah/sarge/internal/util/Assert.java // public final class Assert { // private Assert() { // } // // public static void isNull(Object object) { // if (object != null) // throw new IllegalArgumentException(); // } // // public static void isNull(Object object, String message) { // if (object != null) // throw new IllegalArgumentException(message); // } // // public static void isTrue(boolean expression) { // if (!expression) // throw new IllegalArgumentException(); // } // // public static void isTrue(boolean expression, String errorMessage) { // if (!expression) // throw new IllegalArgumentException(errorMessage); // } // // public static void isTrue(boolean expression, String errorMessage, Object... errorMessageArgs) { // if (!expression) // throw new IllegalArgumentException(String.format(errorMessage, errorMessageArgs)); // } // // public static <T> T notNull(T reference) { // if (reference == null) // throw new IllegalArgumentException(); // return reference; // } // // public static <T> T notNull(T reference, String parameterName) { // if (reference == null) // throw new IllegalArgumentException(parameterName + " cannot be null"); // return reference; // } // // public static void state(boolean expression) { // if (!expression) // throw new IllegalStateException(); // } // // public static void state(boolean expression, String message) { // if (!expression) // throw new IllegalStateException(message); // } // }
import net.jodah.sarge.internal.util.Assert; import java.time.Duration; import java.util.LinkedHashMap; import java.util.Map;
/** * Perform a retry when a failure of any of the {@code causeTypes} occurs, retrying up to * {@code maxRetries} times within the {@code retryWindow} with zero wait time between retries. * * @throws NullPointerException if {@code causeTypes} is null */ public PlanMaker retryOn(Class<? extends Throwable>[] causeTypes, int maxRetries, Duration retryWindow) { return addDirective(Directive.Retry(maxRetries, retryWindow), causeTypes); } /** * Perform a retry when a failure of any of the {@code causeTypes} occurs, retrying up to * {@code maxRetries} times within the {@code retryWindow}, backing off and waiting between each * retry up to {@code maxRetryInterval}. * * @throws NullPointerException if {@code causeType} is null */ public PlanMaker retryOn(Class<? extends Throwable>[] causeTypes, int maxRetries, Duration retryWindow, Duration initialRetryInterval, Duration maxRetryInterval) { return addDirective( Directive.Retry(maxRetries, retryWindow, initialRetryInterval, 2, maxRetryInterval), causeTypes); } /** * @throws IllegalStateException if any of the {@code causeTypes} have already been added. */ PlanMaker addDirective(Directive directive, Class<? extends Throwable>... causeTypes) {
// Path: src/main/java/net/jodah/sarge/internal/util/Assert.java // public final class Assert { // private Assert() { // } // // public static void isNull(Object object) { // if (object != null) // throw new IllegalArgumentException(); // } // // public static void isNull(Object object, String message) { // if (object != null) // throw new IllegalArgumentException(message); // } // // public static void isTrue(boolean expression) { // if (!expression) // throw new IllegalArgumentException(); // } // // public static void isTrue(boolean expression, String errorMessage) { // if (!expression) // throw new IllegalArgumentException(errorMessage); // } // // public static void isTrue(boolean expression, String errorMessage, Object... errorMessageArgs) { // if (!expression) // throw new IllegalArgumentException(String.format(errorMessage, errorMessageArgs)); // } // // public static <T> T notNull(T reference) { // if (reference == null) // throw new IllegalArgumentException(); // return reference; // } // // public static <T> T notNull(T reference, String parameterName) { // if (reference == null) // throw new IllegalArgumentException(parameterName + " cannot be null"); // return reference; // } // // public static void state(boolean expression) { // if (!expression) // throw new IllegalStateException(); // } // // public static void state(boolean expression, String message) { // if (!expression) // throw new IllegalStateException(message); // } // } // Path: src/main/java/net/jodah/sarge/PlanMaker.java import net.jodah.sarge.internal.util.Assert; import java.time.Duration; import java.util.LinkedHashMap; import java.util.Map; /** * Perform a retry when a failure of any of the {@code causeTypes} occurs, retrying up to * {@code maxRetries} times within the {@code retryWindow} with zero wait time between retries. * * @throws NullPointerException if {@code causeTypes} is null */ public PlanMaker retryOn(Class<? extends Throwable>[] causeTypes, int maxRetries, Duration retryWindow) { return addDirective(Directive.Retry(maxRetries, retryWindow), causeTypes); } /** * Perform a retry when a failure of any of the {@code causeTypes} occurs, retrying up to * {@code maxRetries} times within the {@code retryWindow}, backing off and waiting between each * retry up to {@code maxRetryInterval}. * * @throws NullPointerException if {@code causeType} is null */ public PlanMaker retryOn(Class<? extends Throwable>[] causeTypes, int maxRetries, Duration retryWindow, Duration initialRetryInterval, Duration maxRetryInterval) { return addDirective( Directive.Retry(maxRetries, retryWindow, initialRetryInterval, 2, maxRetryInterval), causeTypes); } /** * @throws IllegalStateException if any of the {@code causeTypes} have already been added. */ PlanMaker addDirective(Directive directive, Class<? extends Throwable>... causeTypes) {
Assert.notNull(directive, "directive");
jhalterman/sarge
src/test/java/net/jodah/sarge/internal/SupervisionRegistryTest.java
// Path: src/main/java/net/jodah/sarge/internal/SupervisionRegistry.java // public class SupervisionRegistry { // private final Map<Object, Supervisor> supervisors = new ConcurrentHashMap<Object, Supervisor>(); // private final Map<Object, Plan> plans = new ConcurrentHashMap<Object, Plan>(); // // /** Returns the Plan for the {@code supervised}. */ // public Plan planFor(Object supervised) { // return plans.get(supervised); // } // // public void supervise(Object supervisable, Plan strategy) { // plans.put(supervisable, strategy); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is already supervised // */ // public void supervise(Object supervisable, Supervisor supervisor) { // Supervisor existingSupervisor = supervisors.get(supervisable); // if (existingSupervisor != null) // throw new IllegalArgumentException(supervisable + " is already supervised"); // supervisors.put(supervisable, supervisor); // } // // /** Returns the supervisor for the {@code supervised}. */ // public Supervisor supervisorFor(Object supervised) { // return supervisors.get(supervised); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is not supervised // */ // public void unsupervise(Object supervised) { // if (plans.remove(supervised) == null && supervisors.remove(supervised) == null) // throw new IllegalArgumentException(supervised + " is not supervised"); // } // }
import net.jodah.sarge.internal.SupervisionRegistry; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test;
package net.jodah.sarge.internal; /** * @author Jonathan Halterman */ @Test public class SupervisionRegistryTest {
// Path: src/main/java/net/jodah/sarge/internal/SupervisionRegistry.java // public class SupervisionRegistry { // private final Map<Object, Supervisor> supervisors = new ConcurrentHashMap<Object, Supervisor>(); // private final Map<Object, Plan> plans = new ConcurrentHashMap<Object, Plan>(); // // /** Returns the Plan for the {@code supervised}. */ // public Plan planFor(Object supervised) { // return plans.get(supervised); // } // // public void supervise(Object supervisable, Plan strategy) { // plans.put(supervisable, strategy); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is already supervised // */ // public void supervise(Object supervisable, Supervisor supervisor) { // Supervisor existingSupervisor = supervisors.get(supervisable); // if (existingSupervisor != null) // throw new IllegalArgumentException(supervisable + " is already supervised"); // supervisors.put(supervisable, supervisor); // } // // /** Returns the supervisor for the {@code supervised}. */ // public Supervisor supervisorFor(Object supervised) { // return supervisors.get(supervised); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is not supervised // */ // public void unsupervise(Object supervised) { // if (plans.remove(supervised) == null && supervisors.remove(supervised) == null) // throw new IllegalArgumentException(supervised + " is not supervised"); // } // } // Path: src/test/java/net/jodah/sarge/internal/SupervisionRegistryTest.java import net.jodah.sarge.internal.SupervisionRegistry; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; package net.jodah.sarge.internal; /** * @author Jonathan Halterman */ @Test public class SupervisionRegistryTest {
private SupervisionRegistry registry;
jhalterman/sarge
src/test/java/net/jodah/sarge/functional/UnhandledFailure.java
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // }
import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import org.testng.annotations.Test;
package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class UnhandledFailure extends AbstractTest {
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // Path: src/test/java/net/jodah/sarge/functional/UnhandledFailure.java import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import org.testng.annotations.Test; package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class UnhandledFailure extends AbstractTest {
private static final Plan UNHANDLED_PLAN = new Plan() {
jhalterman/sarge
src/test/java/net/jodah/sarge/functional/UnhandledFailure.java
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // }
import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import org.testng.annotations.Test;
package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class UnhandledFailure extends AbstractTest { private static final Plan UNHANDLED_PLAN = new Plan() {
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // Path: src/test/java/net/jodah/sarge/functional/UnhandledFailure.java import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import org.testng.annotations.Test; package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class UnhandledFailure extends AbstractTest { private static final Plan UNHANDLED_PLAN = new Plan() {
public Directive apply(Throwable cause) {
jhalterman/sarge
src/main/java/net/jodah/sarge/Sarge.java
// Path: src/main/java/net/jodah/sarge/internal/ProxyFactory.java // public class ProxyFactory { // private static final NamingPolicy NAMING_POLICY = new DefaultNamingPolicy() { // @Override // protected String getTag() { // return "BySarge"; // } // }; // // private static final CallbackFilter METHOD_FILTER = new CallbackFilter() { // @Override // public int accept(Method method) { // return method.isBridge() // || (method.getName().equals("finalize") && method.getParameterTypes().length == 0) ? 1 // : 0; // } // }; // // /** // * @throws IllegalArgumentException if the proxy for {@code type} cannot be generated or // * instantiated // */ // public static <T> T proxyFor(Class<T> type, Sarge sarge) { // return proxyFor(type, new Object[]{}, sarge); // } // // public static <T> T proxyFor(Class<T> type, Object[] args, Sarge sarge) { // Class<?> enhanced = null; // // try { // Class[] argumentTypes= new Class[]{}; // if(args.length > 0) { // argumentTypes = new Class[args.length]; // for(int i=0; i<args.length; i++){ // argumentTypes[i] = args[i].getClass(); // } // } // enhanced = proxyClassFor(type); // Enhancer.registerCallbacks(enhanced, new Callback[] { // new CglibMethodInterceptor(new SupervisedInterceptor(sarge)), NoOp.INSTANCE }); // T result = type.cast(enhanced.getDeclaredConstructor(argumentTypes).newInstance(args)); // return result; // } catch (Throwable t) { // throw Errors.errorInstantiatingProxy(type, t); // } finally { // if (enhanced != null) // Enhancer.registerCallbacks(enhanced, null); // } // } // // private static Class<?> proxyClassFor(Class<?> type) { // Enhancer enhancer = new Enhancer(); // enhancer.setSuperclass(type); // enhancer.setUseFactory(false); // enhancer.setUseCache(true); // enhancer.setNamingPolicy(NAMING_POLICY); // enhancer.setCallbackFilter(METHOD_FILTER); // enhancer.setCallbackTypes(new Class[] { MethodInterceptor.class, NoOp.class }); // return enhancer.createClass(); // } // } // // Path: src/main/java/net/jodah/sarge/internal/SupervisionRegistry.java // public class SupervisionRegistry { // private final Map<Object, Supervisor> supervisors = new ConcurrentHashMap<Object, Supervisor>(); // private final Map<Object, Plan> plans = new ConcurrentHashMap<Object, Plan>(); // // /** Returns the Plan for the {@code supervised}. */ // public Plan planFor(Object supervised) { // return plans.get(supervised); // } // // public void supervise(Object supervisable, Plan strategy) { // plans.put(supervisable, strategy); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is already supervised // */ // public void supervise(Object supervisable, Supervisor supervisor) { // Supervisor existingSupervisor = supervisors.get(supervisable); // if (existingSupervisor != null) // throw new IllegalArgumentException(supervisable + " is already supervised"); // supervisors.put(supervisable, supervisor); // } // // /** Returns the supervisor for the {@code supervised}. */ // public Supervisor supervisorFor(Object supervised) { // return supervisors.get(supervised); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is not supervised // */ // public void unsupervise(Object supervised) { // if (plans.remove(supervised) == null && supervisors.remove(supervised) == null) // throw new IllegalArgumentException(supervised + " is not supervised"); // } // } // // Path: src/main/java/net/jodah/sarge/internal/util/Assert.java // public final class Assert { // private Assert() { // } // // public static void isNull(Object object) { // if (object != null) // throw new IllegalArgumentException(); // } // // public static void isNull(Object object, String message) { // if (object != null) // throw new IllegalArgumentException(message); // } // // public static void isTrue(boolean expression) { // if (!expression) // throw new IllegalArgumentException(); // } // // public static void isTrue(boolean expression, String errorMessage) { // if (!expression) // throw new IllegalArgumentException(errorMessage); // } // // public static void isTrue(boolean expression, String errorMessage, Object... errorMessageArgs) { // if (!expression) // throw new IllegalArgumentException(String.format(errorMessage, errorMessageArgs)); // } // // public static <T> T notNull(T reference) { // if (reference == null) // throw new IllegalArgumentException(); // return reference; // } // // public static <T> T notNull(T reference, String parameterName) { // if (reference == null) // throw new IllegalArgumentException(parameterName + " cannot be null"); // return reference; // } // // public static void state(boolean expression) { // if (!expression) // throw new IllegalStateException(); // } // // public static void state(boolean expression, String message) { // if (!expression) // throw new IllegalStateException(message); // } // }
import net.jodah.sarge.internal.ProxyFactory; import net.jodah.sarge.internal.SupervisionRegistry; import net.jodah.sarge.internal.util.Assert;
package net.jodah.sarge; /** * Creates supervised objects, with failures being handled according to a {@link Plan}. * * @author Jonathan Halterman */ public class Sarge { final SupervisionRegistry registry = new SupervisionRegistry(); /** * Returns an instance of the {@code type} that is capable of being supervised by calling one of * the supervise methods. * * @throws NullPointerException if {@code type} is null * @throws IllegalArgumentException if the {@code type} cannot be supervised */ public <T> T supervisable(Class<T> type) {
// Path: src/main/java/net/jodah/sarge/internal/ProxyFactory.java // public class ProxyFactory { // private static final NamingPolicy NAMING_POLICY = new DefaultNamingPolicy() { // @Override // protected String getTag() { // return "BySarge"; // } // }; // // private static final CallbackFilter METHOD_FILTER = new CallbackFilter() { // @Override // public int accept(Method method) { // return method.isBridge() // || (method.getName().equals("finalize") && method.getParameterTypes().length == 0) ? 1 // : 0; // } // }; // // /** // * @throws IllegalArgumentException if the proxy for {@code type} cannot be generated or // * instantiated // */ // public static <T> T proxyFor(Class<T> type, Sarge sarge) { // return proxyFor(type, new Object[]{}, sarge); // } // // public static <T> T proxyFor(Class<T> type, Object[] args, Sarge sarge) { // Class<?> enhanced = null; // // try { // Class[] argumentTypes= new Class[]{}; // if(args.length > 0) { // argumentTypes = new Class[args.length]; // for(int i=0; i<args.length; i++){ // argumentTypes[i] = args[i].getClass(); // } // } // enhanced = proxyClassFor(type); // Enhancer.registerCallbacks(enhanced, new Callback[] { // new CglibMethodInterceptor(new SupervisedInterceptor(sarge)), NoOp.INSTANCE }); // T result = type.cast(enhanced.getDeclaredConstructor(argumentTypes).newInstance(args)); // return result; // } catch (Throwable t) { // throw Errors.errorInstantiatingProxy(type, t); // } finally { // if (enhanced != null) // Enhancer.registerCallbacks(enhanced, null); // } // } // // private static Class<?> proxyClassFor(Class<?> type) { // Enhancer enhancer = new Enhancer(); // enhancer.setSuperclass(type); // enhancer.setUseFactory(false); // enhancer.setUseCache(true); // enhancer.setNamingPolicy(NAMING_POLICY); // enhancer.setCallbackFilter(METHOD_FILTER); // enhancer.setCallbackTypes(new Class[] { MethodInterceptor.class, NoOp.class }); // return enhancer.createClass(); // } // } // // Path: src/main/java/net/jodah/sarge/internal/SupervisionRegistry.java // public class SupervisionRegistry { // private final Map<Object, Supervisor> supervisors = new ConcurrentHashMap<Object, Supervisor>(); // private final Map<Object, Plan> plans = new ConcurrentHashMap<Object, Plan>(); // // /** Returns the Plan for the {@code supervised}. */ // public Plan planFor(Object supervised) { // return plans.get(supervised); // } // // public void supervise(Object supervisable, Plan strategy) { // plans.put(supervisable, strategy); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is already supervised // */ // public void supervise(Object supervisable, Supervisor supervisor) { // Supervisor existingSupervisor = supervisors.get(supervisable); // if (existingSupervisor != null) // throw new IllegalArgumentException(supervisable + " is already supervised"); // supervisors.put(supervisable, supervisor); // } // // /** Returns the supervisor for the {@code supervised}. */ // public Supervisor supervisorFor(Object supervised) { // return supervisors.get(supervised); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is not supervised // */ // public void unsupervise(Object supervised) { // if (plans.remove(supervised) == null && supervisors.remove(supervised) == null) // throw new IllegalArgumentException(supervised + " is not supervised"); // } // } // // Path: src/main/java/net/jodah/sarge/internal/util/Assert.java // public final class Assert { // private Assert() { // } // // public static void isNull(Object object) { // if (object != null) // throw new IllegalArgumentException(); // } // // public static void isNull(Object object, String message) { // if (object != null) // throw new IllegalArgumentException(message); // } // // public static void isTrue(boolean expression) { // if (!expression) // throw new IllegalArgumentException(); // } // // public static void isTrue(boolean expression, String errorMessage) { // if (!expression) // throw new IllegalArgumentException(errorMessage); // } // // public static void isTrue(boolean expression, String errorMessage, Object... errorMessageArgs) { // if (!expression) // throw new IllegalArgumentException(String.format(errorMessage, errorMessageArgs)); // } // // public static <T> T notNull(T reference) { // if (reference == null) // throw new IllegalArgumentException(); // return reference; // } // // public static <T> T notNull(T reference, String parameterName) { // if (reference == null) // throw new IllegalArgumentException(parameterName + " cannot be null"); // return reference; // } // // public static void state(boolean expression) { // if (!expression) // throw new IllegalStateException(); // } // // public static void state(boolean expression, String message) { // if (!expression) // throw new IllegalStateException(message); // } // } // Path: src/main/java/net/jodah/sarge/Sarge.java import net.jodah.sarge.internal.ProxyFactory; import net.jodah.sarge.internal.SupervisionRegistry; import net.jodah.sarge.internal.util.Assert; package net.jodah.sarge; /** * Creates supervised objects, with failures being handled according to a {@link Plan}. * * @author Jonathan Halterman */ public class Sarge { final SupervisionRegistry registry = new SupervisionRegistry(); /** * Returns an instance of the {@code type} that is capable of being supervised by calling one of * the supervise methods. * * @throws NullPointerException if {@code type} is null * @throws IllegalArgumentException if the {@code type} cannot be supervised */ public <T> T supervisable(Class<T> type) {
Assert.notNull(type, "type");
jhalterman/sarge
src/main/java/net/jodah/sarge/Sarge.java
// Path: src/main/java/net/jodah/sarge/internal/ProxyFactory.java // public class ProxyFactory { // private static final NamingPolicy NAMING_POLICY = new DefaultNamingPolicy() { // @Override // protected String getTag() { // return "BySarge"; // } // }; // // private static final CallbackFilter METHOD_FILTER = new CallbackFilter() { // @Override // public int accept(Method method) { // return method.isBridge() // || (method.getName().equals("finalize") && method.getParameterTypes().length == 0) ? 1 // : 0; // } // }; // // /** // * @throws IllegalArgumentException if the proxy for {@code type} cannot be generated or // * instantiated // */ // public static <T> T proxyFor(Class<T> type, Sarge sarge) { // return proxyFor(type, new Object[]{}, sarge); // } // // public static <T> T proxyFor(Class<T> type, Object[] args, Sarge sarge) { // Class<?> enhanced = null; // // try { // Class[] argumentTypes= new Class[]{}; // if(args.length > 0) { // argumentTypes = new Class[args.length]; // for(int i=0; i<args.length; i++){ // argumentTypes[i] = args[i].getClass(); // } // } // enhanced = proxyClassFor(type); // Enhancer.registerCallbacks(enhanced, new Callback[] { // new CglibMethodInterceptor(new SupervisedInterceptor(sarge)), NoOp.INSTANCE }); // T result = type.cast(enhanced.getDeclaredConstructor(argumentTypes).newInstance(args)); // return result; // } catch (Throwable t) { // throw Errors.errorInstantiatingProxy(type, t); // } finally { // if (enhanced != null) // Enhancer.registerCallbacks(enhanced, null); // } // } // // private static Class<?> proxyClassFor(Class<?> type) { // Enhancer enhancer = new Enhancer(); // enhancer.setSuperclass(type); // enhancer.setUseFactory(false); // enhancer.setUseCache(true); // enhancer.setNamingPolicy(NAMING_POLICY); // enhancer.setCallbackFilter(METHOD_FILTER); // enhancer.setCallbackTypes(new Class[] { MethodInterceptor.class, NoOp.class }); // return enhancer.createClass(); // } // } // // Path: src/main/java/net/jodah/sarge/internal/SupervisionRegistry.java // public class SupervisionRegistry { // private final Map<Object, Supervisor> supervisors = new ConcurrentHashMap<Object, Supervisor>(); // private final Map<Object, Plan> plans = new ConcurrentHashMap<Object, Plan>(); // // /** Returns the Plan for the {@code supervised}. */ // public Plan planFor(Object supervised) { // return plans.get(supervised); // } // // public void supervise(Object supervisable, Plan strategy) { // plans.put(supervisable, strategy); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is already supervised // */ // public void supervise(Object supervisable, Supervisor supervisor) { // Supervisor existingSupervisor = supervisors.get(supervisable); // if (existingSupervisor != null) // throw new IllegalArgumentException(supervisable + " is already supervised"); // supervisors.put(supervisable, supervisor); // } // // /** Returns the supervisor for the {@code supervised}. */ // public Supervisor supervisorFor(Object supervised) { // return supervisors.get(supervised); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is not supervised // */ // public void unsupervise(Object supervised) { // if (plans.remove(supervised) == null && supervisors.remove(supervised) == null) // throw new IllegalArgumentException(supervised + " is not supervised"); // } // } // // Path: src/main/java/net/jodah/sarge/internal/util/Assert.java // public final class Assert { // private Assert() { // } // // public static void isNull(Object object) { // if (object != null) // throw new IllegalArgumentException(); // } // // public static void isNull(Object object, String message) { // if (object != null) // throw new IllegalArgumentException(message); // } // // public static void isTrue(boolean expression) { // if (!expression) // throw new IllegalArgumentException(); // } // // public static void isTrue(boolean expression, String errorMessage) { // if (!expression) // throw new IllegalArgumentException(errorMessage); // } // // public static void isTrue(boolean expression, String errorMessage, Object... errorMessageArgs) { // if (!expression) // throw new IllegalArgumentException(String.format(errorMessage, errorMessageArgs)); // } // // public static <T> T notNull(T reference) { // if (reference == null) // throw new IllegalArgumentException(); // return reference; // } // // public static <T> T notNull(T reference, String parameterName) { // if (reference == null) // throw new IllegalArgumentException(parameterName + " cannot be null"); // return reference; // } // // public static void state(boolean expression) { // if (!expression) // throw new IllegalStateException(); // } // // public static void state(boolean expression, String message) { // if (!expression) // throw new IllegalStateException(message); // } // }
import net.jodah.sarge.internal.ProxyFactory; import net.jodah.sarge.internal.SupervisionRegistry; import net.jodah.sarge.internal.util.Assert;
package net.jodah.sarge; /** * Creates supervised objects, with failures being handled according to a {@link Plan}. * * @author Jonathan Halterman */ public class Sarge { final SupervisionRegistry registry = new SupervisionRegistry(); /** * Returns an instance of the {@code type} that is capable of being supervised by calling one of * the supervise methods. * * @throws NullPointerException if {@code type} is null * @throws IllegalArgumentException if the {@code type} cannot be supervised */ public <T> T supervisable(Class<T> type) { Assert.notNull(type, "type");
// Path: src/main/java/net/jodah/sarge/internal/ProxyFactory.java // public class ProxyFactory { // private static final NamingPolicy NAMING_POLICY = new DefaultNamingPolicy() { // @Override // protected String getTag() { // return "BySarge"; // } // }; // // private static final CallbackFilter METHOD_FILTER = new CallbackFilter() { // @Override // public int accept(Method method) { // return method.isBridge() // || (method.getName().equals("finalize") && method.getParameterTypes().length == 0) ? 1 // : 0; // } // }; // // /** // * @throws IllegalArgumentException if the proxy for {@code type} cannot be generated or // * instantiated // */ // public static <T> T proxyFor(Class<T> type, Sarge sarge) { // return proxyFor(type, new Object[]{}, sarge); // } // // public static <T> T proxyFor(Class<T> type, Object[] args, Sarge sarge) { // Class<?> enhanced = null; // // try { // Class[] argumentTypes= new Class[]{}; // if(args.length > 0) { // argumentTypes = new Class[args.length]; // for(int i=0; i<args.length; i++){ // argumentTypes[i] = args[i].getClass(); // } // } // enhanced = proxyClassFor(type); // Enhancer.registerCallbacks(enhanced, new Callback[] { // new CglibMethodInterceptor(new SupervisedInterceptor(sarge)), NoOp.INSTANCE }); // T result = type.cast(enhanced.getDeclaredConstructor(argumentTypes).newInstance(args)); // return result; // } catch (Throwable t) { // throw Errors.errorInstantiatingProxy(type, t); // } finally { // if (enhanced != null) // Enhancer.registerCallbacks(enhanced, null); // } // } // // private static Class<?> proxyClassFor(Class<?> type) { // Enhancer enhancer = new Enhancer(); // enhancer.setSuperclass(type); // enhancer.setUseFactory(false); // enhancer.setUseCache(true); // enhancer.setNamingPolicy(NAMING_POLICY); // enhancer.setCallbackFilter(METHOD_FILTER); // enhancer.setCallbackTypes(new Class[] { MethodInterceptor.class, NoOp.class }); // return enhancer.createClass(); // } // } // // Path: src/main/java/net/jodah/sarge/internal/SupervisionRegistry.java // public class SupervisionRegistry { // private final Map<Object, Supervisor> supervisors = new ConcurrentHashMap<Object, Supervisor>(); // private final Map<Object, Plan> plans = new ConcurrentHashMap<Object, Plan>(); // // /** Returns the Plan for the {@code supervised}. */ // public Plan planFor(Object supervised) { // return plans.get(supervised); // } // // public void supervise(Object supervisable, Plan strategy) { // plans.put(supervisable, strategy); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is already supervised // */ // public void supervise(Object supervisable, Supervisor supervisor) { // Supervisor existingSupervisor = supervisors.get(supervisable); // if (existingSupervisor != null) // throw new IllegalArgumentException(supervisable + " is already supervised"); // supervisors.put(supervisable, supervisor); // } // // /** Returns the supervisor for the {@code supervised}. */ // public Supervisor supervisorFor(Object supervised) { // return supervisors.get(supervised); // } // // /** // * @throws IllegalArgumentException if {@code supervised} is not supervised // */ // public void unsupervise(Object supervised) { // if (plans.remove(supervised) == null && supervisors.remove(supervised) == null) // throw new IllegalArgumentException(supervised + " is not supervised"); // } // } // // Path: src/main/java/net/jodah/sarge/internal/util/Assert.java // public final class Assert { // private Assert() { // } // // public static void isNull(Object object) { // if (object != null) // throw new IllegalArgumentException(); // } // // public static void isNull(Object object, String message) { // if (object != null) // throw new IllegalArgumentException(message); // } // // public static void isTrue(boolean expression) { // if (!expression) // throw new IllegalArgumentException(); // } // // public static void isTrue(boolean expression, String errorMessage) { // if (!expression) // throw new IllegalArgumentException(errorMessage); // } // // public static void isTrue(boolean expression, String errorMessage, Object... errorMessageArgs) { // if (!expression) // throw new IllegalArgumentException(String.format(errorMessage, errorMessageArgs)); // } // // public static <T> T notNull(T reference) { // if (reference == null) // throw new IllegalArgumentException(); // return reference; // } // // public static <T> T notNull(T reference, String parameterName) { // if (reference == null) // throw new IllegalArgumentException(parameterName + " cannot be null"); // return reference; // } // // public static void state(boolean expression) { // if (!expression) // throw new IllegalStateException(); // } // // public static void state(boolean expression, String message) { // if (!expression) // throw new IllegalStateException(message); // } // } // Path: src/main/java/net/jodah/sarge/Sarge.java import net.jodah.sarge.internal.ProxyFactory; import net.jodah.sarge.internal.SupervisionRegistry; import net.jodah.sarge.internal.util.Assert; package net.jodah.sarge; /** * Creates supervised objects, with failures being handled according to a {@link Plan}. * * @author Jonathan Halterman */ public class Sarge { final SupervisionRegistry registry = new SupervisionRegistry(); /** * Returns an instance of the {@code type} that is capable of being supervised by calling one of * the supervise methods. * * @throws NullPointerException if {@code type} is null * @throws IllegalArgumentException if the {@code type} cannot be supervised */ public <T> T supervisable(Class<T> type) { Assert.notNull(type, "type");
return ProxyFactory.proxyFor(type, this);
jhalterman/sarge
src/test/java/net/jodah/sarge/functional/SupervisorOverride.java
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // } // // Path: src/main/java/net/jodah/sarge/Supervisor.java // public interface Supervisor { // /** Returns the plan to be used when supervising child objects. */ // Plan plan(); // }
import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import net.jodah.sarge.Supervisor; import org.testng.annotations.Test;
package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SupervisorOverride extends AbstractTest {
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // } // // Path: src/main/java/net/jodah/sarge/Supervisor.java // public interface Supervisor { // /** Returns the plan to be used when supervising child objects. */ // Plan plan(); // } // Path: src/test/java/net/jodah/sarge/functional/SupervisorOverride.java import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import net.jodah.sarge.Supervisor; import org.testng.annotations.Test; package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SupervisorOverride extends AbstractTest {
private static final Plan RETHROW_STRATEGY = new Plan() {
jhalterman/sarge
src/test/java/net/jodah/sarge/functional/SupervisorOverride.java
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // } // // Path: src/main/java/net/jodah/sarge/Supervisor.java // public interface Supervisor { // /** Returns the plan to be used when supervising child objects. */ // Plan plan(); // }
import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import net.jodah.sarge.Supervisor; import org.testng.annotations.Test;
package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SupervisorOverride extends AbstractTest { private static final Plan RETHROW_STRATEGY = new Plan() {
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // } // // Path: src/main/java/net/jodah/sarge/Supervisor.java // public interface Supervisor { // /** Returns the plan to be used when supervising child objects. */ // Plan plan(); // } // Path: src/test/java/net/jodah/sarge/functional/SupervisorOverride.java import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import net.jodah.sarge.Supervisor; import org.testng.annotations.Test; package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SupervisorOverride extends AbstractTest { private static final Plan RETHROW_STRATEGY = new Plan() {
public Directive apply(Throwable cause) {
jhalterman/sarge
src/test/java/net/jodah/sarge/functional/SupervisorOverride.java
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // } // // Path: src/main/java/net/jodah/sarge/Supervisor.java // public interface Supervisor { // /** Returns the plan to be used when supervising child objects. */ // Plan plan(); // }
import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import net.jodah.sarge.Supervisor; import org.testng.annotations.Test;
package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SupervisorOverride extends AbstractTest { private static final Plan RETHROW_STRATEGY = new Plan() { public Directive apply(Throwable cause) { return Directive.Rethrow; } }; private static final Plan RESUME_STRATEGY = new Plan() { public Directive apply(Throwable cause) { return Directive.Resume; } };
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // } // // Path: src/main/java/net/jodah/sarge/Supervisor.java // public interface Supervisor { // /** Returns the plan to be used when supervising child objects. */ // Plan plan(); // } // Path: src/test/java/net/jodah/sarge/functional/SupervisorOverride.java import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import net.jodah.sarge.Supervisor; import org.testng.annotations.Test; package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SupervisorOverride extends AbstractTest { private static final Plan RETHROW_STRATEGY = new Plan() { public Directive apply(Throwable cause) { return Directive.Rethrow; } }; private static final Plan RESUME_STRATEGY = new Plan() { public Directive apply(Throwable cause) { return Directive.Resume; } };
static class Child implements SelfSupervisor {
jhalterman/sarge
src/test/java/net/jodah/sarge/functional/SupervisorOverride.java
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // } // // Path: src/main/java/net/jodah/sarge/Supervisor.java // public interface Supervisor { // /** Returns the plan to be used when supervising child objects. */ // Plan plan(); // }
import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import net.jodah.sarge.Supervisor; import org.testng.annotations.Test;
package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SupervisorOverride extends AbstractTest { private static final Plan RETHROW_STRATEGY = new Plan() { public Directive apply(Throwable cause) { return Directive.Rethrow; } }; private static final Plan RESUME_STRATEGY = new Plan() { public Directive apply(Throwable cause) { return Directive.Resume; } }; static class Child implements SelfSupervisor { public Plan selfPlan() { return RETHROW_STRATEGY; } void doSomething() { throw new RuntimeException(); } }
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // } // // Path: src/main/java/net/jodah/sarge/Supervisor.java // public interface Supervisor { // /** Returns the plan to be used when supervising child objects. */ // Plan plan(); // } // Path: src/test/java/net/jodah/sarge/functional/SupervisorOverride.java import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import net.jodah.sarge.Supervisor; import org.testng.annotations.Test; package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SupervisorOverride extends AbstractTest { private static final Plan RETHROW_STRATEGY = new Plan() { public Directive apply(Throwable cause) { return Directive.Rethrow; } }; private static final Plan RESUME_STRATEGY = new Plan() { public Directive apply(Throwable cause) { return Directive.Resume; } }; static class Child implements SelfSupervisor { public Plan selfPlan() { return RETHROW_STRATEGY; } void doSomething() { throw new RuntimeException(); } }
static class Parent implements Supervisor {
jhalterman/sarge
src/test/java/net/jodah/sarge/functional/SelfSupervisionTest.java
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // }
import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.time.Duration; import java.util.concurrent.atomic.AtomicInteger; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail;
package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SelfSupervisionTest extends AbstractTest { private static int counter;
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // } // Path: src/test/java/net/jodah/sarge/functional/SelfSupervisionTest.java import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.time.Duration; import java.util.concurrent.atomic.AtomicInteger; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SelfSupervisionTest extends AbstractTest { private static int counter;
private static final Plan RETRY_PLAN = new Plan() {
jhalterman/sarge
src/test/java/net/jodah/sarge/functional/SelfSupervisionTest.java
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // }
import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.time.Duration; import java.util.concurrent.atomic.AtomicInteger; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail;
package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SelfSupervisionTest extends AbstractTest { private static int counter; private static final Plan RETRY_PLAN = new Plan() {
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // } // Path: src/test/java/net/jodah/sarge/functional/SelfSupervisionTest.java import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.time.Duration; import java.util.concurrent.atomic.AtomicInteger; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; package net.jodah.sarge.functional; /** * @author Jonathan Halterman */ @Test public class SelfSupervisionTest extends AbstractTest { private static int counter; private static final Plan RETRY_PLAN = new Plan() {
public Directive apply(Throwable cause) {
jhalterman/sarge
src/test/java/net/jodah/sarge/functional/SelfSupervisionTest.java
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // }
import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.time.Duration; import java.util.concurrent.atomic.AtomicInteger; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail;
}; private static final Plan RESUME_PLAN = new Plan() { public Directive apply(Throwable cause) { return Directive.Resume; } }; static class Foo { void doSomething() { counter++; throw new IllegalStateException(); } void doSomethingElse(AtomicInteger v) { v.set(v.get() + 1); } void doSomethingEscalated() { counter++; throw new IllegalStateException(); } void throwIt(BinaryException e) { if (e.rethrow) { e.rethrow = false; throw e; } } }
// Path: src/test/java/net/jodah/sarge/AbstractTest.java // public abstract class AbstractTest { // protected Sarge sarge; // // @BeforeMethod // protected void beforeMethod() { // sarge = new Sarge(); // } // } // // Path: src/main/java/net/jodah/sarge/Directive.java // public class Directive { // /** // * Resume supervision, re-throwing the failure from the point of invocation if a result is // * expected. // */ // public static final Directive Resume = new Directive() { // @Override // public String toString() { // return "Resume Directive"; // } // }; // // /** Re-throws the failure from the point of invocation. */ // public static final Directive Rethrow = new Directive() { // @Override // public String toString() { // return "Rethrow Directive"; // } // }; // // /** Escalates the failure to the supervisor of the supervisor. */ // public static final Directive Escalate = new Directive() { // @Override // public String toString() { // return "Escalate Directive"; // } // }; // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow) { // return new RetryDirective(maxRetries, retryWindow); // } // // /** Retries the method invocation. */ // public static Directive Retry(int maxRetries, Duration retryWindow, // Duration initialRetryInterval, double backoffExponent, Duration maxRetryInterval) { // return new RetryDirective(maxRetries, retryWindow, initialRetryInterval, backoffExponent, // maxRetryInterval); // } // } // // Path: src/main/java/net/jodah/sarge/Plan.java // public interface Plan { // /** // * Applies the plan to the {@code failure} returning a {@link Directive}. // * // * @param failure to handle // * @return Directive to carry out // */ // Directive apply(Throwable failure); // } // // Path: src/main/java/net/jodah/sarge/SelfSupervisor.java // public interface SelfSupervisor { // /** Returns the plan to be used when supervising itself. */ // Plan selfPlan(); // } // Path: src/test/java/net/jodah/sarge/functional/SelfSupervisionTest.java import net.jodah.sarge.AbstractTest; import net.jodah.sarge.Directive; import net.jodah.sarge.Plan; import net.jodah.sarge.SelfSupervisor; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.time.Duration; import java.util.concurrent.atomic.AtomicInteger; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; }; private static final Plan RESUME_PLAN = new Plan() { public Directive apply(Throwable cause) { return Directive.Resume; } }; static class Foo { void doSomething() { counter++; throw new IllegalStateException(); } void doSomethingElse(AtomicInteger v) { v.set(v.get() + 1); } void doSomethingEscalated() { counter++; throw new IllegalStateException(); } void throwIt(BinaryException e) { if (e.rethrow) { e.rethrow = false; throw e; } } }
static class FooEscalate implements SelfSupervisor {
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/ArtifactoryAuthenticationMockTest.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryAuthentication.java // public class ArtifactoryAuthentication extends Credentials { // // private final AuthenticationType authType; // // /** // * Create instance of ArtifactoryAuthentication // * // * @param authValue value to use for authentication type HTTP header. // * @param authType authentication type (e.g. Basic, Bearer, Anonymous). // */ // private ArtifactoryAuthentication(final String authValue, final AuthenticationType authType) { // super(null, authType == AuthenticationType.Basic && authValue.contains(":") // ? base64().encode(authValue.getBytes()) // : authValue); // this.authType = authType; // } // // @Nullable // public String authValue() { // return this.credential; // } // // public AuthenticationType authType() { // return authType; // } // // public static Builder builder() { // return new Builder(); // } // // public static class Builder { // // private String authValue; // private AuthenticationType authType; // // /** // * Set 'Basic' credentials. // * // * @param basicCredentials value to use for 'Basic' credentials. // * @return this Builder. // */ // public Builder credentials(final String basicCredentials) { // this.authValue = Objects.requireNonNull(basicCredentials); // this.authType = AuthenticationType.Basic; // return this; // } // // /** // * Set 'Bearer' credentials. // * // * @param tokenCredentials value to use for 'Bearer' credentials. // * @return this Builder. // */ // public Builder token(final String tokenCredentials) { // this.authValue = Objects.requireNonNull(tokenCredentials); // this.authType = AuthenticationType.Bearer; // return this; // } // // /** // * Build and instance of ArtifactoryCredentials. // * // * @return instance of ArtifactoryCredentials. // */ // public ArtifactoryAuthentication build() { // return new ArtifactoryAuthentication(authValue, authType != null // ? authType // : AuthenticationType.Anonymous); // } // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/auth/AuthenticationType.java // public enum AuthenticationType { // // Basic("Basic"), // Bearer("Bearer"), // Anonymous(""); // // private final String type; // // private AuthenticationType(final String type) { // this.type = type; // } // // @Override // public String toString() { // return type; // } // }
import static org.assertj.core.api.Assertions.assertThat; import com.cdancy.artifactory.rest.ArtifactoryAuthentication; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.cdancy.artifactory.rest.auth.AuthenticationType; import org.testng.annotations.Test;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Test(groups = "unit", testName = "ArtifactoryAuthenticationMockTest") public class ArtifactoryAuthenticationMockTest extends BaseArtifactoryMockTest { private final String unencodedAuth = "hello:world"; private final String encodedAuth = "aGVsbG86d29ybGQ="; public void testCreateAnonymousAuth() {
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryAuthentication.java // public class ArtifactoryAuthentication extends Credentials { // // private final AuthenticationType authType; // // /** // * Create instance of ArtifactoryAuthentication // * // * @param authValue value to use for authentication type HTTP header. // * @param authType authentication type (e.g. Basic, Bearer, Anonymous). // */ // private ArtifactoryAuthentication(final String authValue, final AuthenticationType authType) { // super(null, authType == AuthenticationType.Basic && authValue.contains(":") // ? base64().encode(authValue.getBytes()) // : authValue); // this.authType = authType; // } // // @Nullable // public String authValue() { // return this.credential; // } // // public AuthenticationType authType() { // return authType; // } // // public static Builder builder() { // return new Builder(); // } // // public static class Builder { // // private String authValue; // private AuthenticationType authType; // // /** // * Set 'Basic' credentials. // * // * @param basicCredentials value to use for 'Basic' credentials. // * @return this Builder. // */ // public Builder credentials(final String basicCredentials) { // this.authValue = Objects.requireNonNull(basicCredentials); // this.authType = AuthenticationType.Basic; // return this; // } // // /** // * Set 'Bearer' credentials. // * // * @param tokenCredentials value to use for 'Bearer' credentials. // * @return this Builder. // */ // public Builder token(final String tokenCredentials) { // this.authValue = Objects.requireNonNull(tokenCredentials); // this.authType = AuthenticationType.Bearer; // return this; // } // // /** // * Build and instance of ArtifactoryCredentials. // * // * @return instance of ArtifactoryCredentials. // */ // public ArtifactoryAuthentication build() { // return new ArtifactoryAuthentication(authValue, authType != null // ? authType // : AuthenticationType.Anonymous); // } // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/auth/AuthenticationType.java // public enum AuthenticationType { // // Basic("Basic"), // Bearer("Bearer"), // Anonymous(""); // // private final String type; // // private AuthenticationType(final String type) { // this.type = type; // } // // @Override // public String toString() { // return type; // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/ArtifactoryAuthenticationMockTest.java import static org.assertj.core.api.Assertions.assertThat; import com.cdancy.artifactory.rest.ArtifactoryAuthentication; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.cdancy.artifactory.rest.auth.AuthenticationType; import org.testng.annotations.Test; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Test(groups = "unit", testName = "ArtifactoryAuthenticationMockTest") public class ArtifactoryAuthenticationMockTest extends BaseArtifactoryMockTest { private final String unencodedAuth = "hello:world"; private final String encodedAuth = "aGVsbG86d29ybGQ="; public void testCreateAnonymousAuth() {
final ArtifactoryAuthentication auth = ArtifactoryAuthentication.builder().build();
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/ArtifactoryAuthenticationMockTest.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryAuthentication.java // public class ArtifactoryAuthentication extends Credentials { // // private final AuthenticationType authType; // // /** // * Create instance of ArtifactoryAuthentication // * // * @param authValue value to use for authentication type HTTP header. // * @param authType authentication type (e.g. Basic, Bearer, Anonymous). // */ // private ArtifactoryAuthentication(final String authValue, final AuthenticationType authType) { // super(null, authType == AuthenticationType.Basic && authValue.contains(":") // ? base64().encode(authValue.getBytes()) // : authValue); // this.authType = authType; // } // // @Nullable // public String authValue() { // return this.credential; // } // // public AuthenticationType authType() { // return authType; // } // // public static Builder builder() { // return new Builder(); // } // // public static class Builder { // // private String authValue; // private AuthenticationType authType; // // /** // * Set 'Basic' credentials. // * // * @param basicCredentials value to use for 'Basic' credentials. // * @return this Builder. // */ // public Builder credentials(final String basicCredentials) { // this.authValue = Objects.requireNonNull(basicCredentials); // this.authType = AuthenticationType.Basic; // return this; // } // // /** // * Set 'Bearer' credentials. // * // * @param tokenCredentials value to use for 'Bearer' credentials. // * @return this Builder. // */ // public Builder token(final String tokenCredentials) { // this.authValue = Objects.requireNonNull(tokenCredentials); // this.authType = AuthenticationType.Bearer; // return this; // } // // /** // * Build and instance of ArtifactoryCredentials. // * // * @return instance of ArtifactoryCredentials. // */ // public ArtifactoryAuthentication build() { // return new ArtifactoryAuthentication(authValue, authType != null // ? authType // : AuthenticationType.Anonymous); // } // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/auth/AuthenticationType.java // public enum AuthenticationType { // // Basic("Basic"), // Bearer("Bearer"), // Anonymous(""); // // private final String type; // // private AuthenticationType(final String type) { // this.type = type; // } // // @Override // public String toString() { // return type; // } // }
import static org.assertj.core.api.Assertions.assertThat; import com.cdancy.artifactory.rest.ArtifactoryAuthentication; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.cdancy.artifactory.rest.auth.AuthenticationType; import org.testng.annotations.Test;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Test(groups = "unit", testName = "ArtifactoryAuthenticationMockTest") public class ArtifactoryAuthenticationMockTest extends BaseArtifactoryMockTest { private final String unencodedAuth = "hello:world"; private final String encodedAuth = "aGVsbG86d29ybGQ="; public void testCreateAnonymousAuth() { final ArtifactoryAuthentication auth = ArtifactoryAuthentication.builder().build(); assertThat(auth).isNotNull(); assertThat(auth.authValue()).isNull();
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryAuthentication.java // public class ArtifactoryAuthentication extends Credentials { // // private final AuthenticationType authType; // // /** // * Create instance of ArtifactoryAuthentication // * // * @param authValue value to use for authentication type HTTP header. // * @param authType authentication type (e.g. Basic, Bearer, Anonymous). // */ // private ArtifactoryAuthentication(final String authValue, final AuthenticationType authType) { // super(null, authType == AuthenticationType.Basic && authValue.contains(":") // ? base64().encode(authValue.getBytes()) // : authValue); // this.authType = authType; // } // // @Nullable // public String authValue() { // return this.credential; // } // // public AuthenticationType authType() { // return authType; // } // // public static Builder builder() { // return new Builder(); // } // // public static class Builder { // // private String authValue; // private AuthenticationType authType; // // /** // * Set 'Basic' credentials. // * // * @param basicCredentials value to use for 'Basic' credentials. // * @return this Builder. // */ // public Builder credentials(final String basicCredentials) { // this.authValue = Objects.requireNonNull(basicCredentials); // this.authType = AuthenticationType.Basic; // return this; // } // // /** // * Set 'Bearer' credentials. // * // * @param tokenCredentials value to use for 'Bearer' credentials. // * @return this Builder. // */ // public Builder token(final String tokenCredentials) { // this.authValue = Objects.requireNonNull(tokenCredentials); // this.authType = AuthenticationType.Bearer; // return this; // } // // /** // * Build and instance of ArtifactoryCredentials. // * // * @return instance of ArtifactoryCredentials. // */ // public ArtifactoryAuthentication build() { // return new ArtifactoryAuthentication(authValue, authType != null // ? authType // : AuthenticationType.Anonymous); // } // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/auth/AuthenticationType.java // public enum AuthenticationType { // // Basic("Basic"), // Bearer("Bearer"), // Anonymous(""); // // private final String type; // // private AuthenticationType(final String type) { // this.type = type; // } // // @Override // public String toString() { // return type; // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/ArtifactoryAuthenticationMockTest.java import static org.assertj.core.api.Assertions.assertThat; import com.cdancy.artifactory.rest.ArtifactoryAuthentication; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.cdancy.artifactory.rest.auth.AuthenticationType; import org.testng.annotations.Test; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Test(groups = "unit", testName = "ArtifactoryAuthenticationMockTest") public class ArtifactoryAuthenticationMockTest extends BaseArtifactoryMockTest { private final String unencodedAuth = "hello:world"; private final String encodedAuth = "aGVsbG86d29ybGQ="; public void testCreateAnonymousAuth() { final ArtifactoryAuthentication auth = ArtifactoryAuthentication.builder().build(); assertThat(auth).isNotNull(); assertThat(auth.authValue()).isNull();
assertThat(auth.authType()).isEqualTo(AuthenticationType.Anonymous);
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java
// Path: src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryAuthenticationModule.java // public class ArtifactoryAuthenticationModule extends AbstractModule { // // private final ArtifactoryAuthentication authentication; // // public ArtifactoryAuthenticationModule(final ArtifactoryAuthentication authentication) { // this.authentication = Objects.requireNonNull(authentication); // } // // @Override // protected void configure() { // bind(ArtifactoryAuthentication.class).toProvider(new ArtifactoryAuthenticationProvider(authentication)); // } // }
import com.google.common.base.Charsets; import com.google.common.base.Throwables; import com.google.common.collect.Lists; import com.squareup.okhttp.mockwebserver.MockWebServer; import com.squareup.okhttp.mockwebserver.RecordedRequest; import com.cdancy.artifactory.rest.config.ArtifactoryAuthenticationModule; import static org.assertj.core.api.Assertions.assertThat; import static org.jclouds.util.Strings2.toStringAndClose; import java.io.IOException; import java.net.URL; import java.util.Properties; import java.util.UUID; import javax.ws.rs.core.HttpHeaders; import org.jclouds.Constants; import org.jclouds.ContextBuilder;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest; /** * Base class for all Artifactory mock tests. */ public class BaseArtifactoryMockTest { protected String provider; public BaseArtifactoryMockTest() { provider = "artifactory"; } public ArtifactoryApi api(URL url) { final ArtifactoryAuthentication creds = ArtifactoryAuthentication .builder() .credentials("hello:world") .build();
// Path: src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryAuthenticationModule.java // public class ArtifactoryAuthenticationModule extends AbstractModule { // // private final ArtifactoryAuthentication authentication; // // public ArtifactoryAuthenticationModule(final ArtifactoryAuthentication authentication) { // this.authentication = Objects.requireNonNull(authentication); // } // // @Override // protected void configure() { // bind(ArtifactoryAuthentication.class).toProvider(new ArtifactoryAuthenticationProvider(authentication)); // } // } // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java import com.google.common.base.Charsets; import com.google.common.base.Throwables; import com.google.common.collect.Lists; import com.squareup.okhttp.mockwebserver.MockWebServer; import com.squareup.okhttp.mockwebserver.RecordedRequest; import com.cdancy.artifactory.rest.config.ArtifactoryAuthenticationModule; import static org.assertj.core.api.Assertions.assertThat; import static org.jclouds.util.Strings2.toStringAndClose; import java.io.IOException; import java.net.URL; import java.util.Properties; import java.util.UUID; import javax.ws.rs.core.HttpHeaders; import org.jclouds.Constants; import org.jclouds.ContextBuilder; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest; /** * Base class for all Artifactory mock tests. */ public class BaseArtifactoryMockTest { protected String provider; public BaseArtifactoryMockTest() { provider = "artifactory"; } public ArtifactoryApi api(URL url) { final ArtifactoryAuthentication creds = ArtifactoryAuthentication .builder() .credentials("hello:world") .build();
final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds);
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/features/SystemApi.java
// Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // }
import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.core.MediaType; import com.cdancy.artifactory.rest.domain.system.Version; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import org.jclouds.rest.annotations.RequestFilters;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api/system") @RequestFilters(ArtifactoryAuthenticationFilter.class) public interface SystemApi { @Named("system:version") @Path("/version") @Consumes(MediaType.APPLICATION_JSON) @GET
// Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // } // Path: src/main/java/com/cdancy/artifactory/rest/features/SystemApi.java import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.core.MediaType; import com.cdancy.artifactory.rest.domain.system.Version; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import org.jclouds.rest.annotations.RequestFilters; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api/system") @RequestFilters(ArtifactoryAuthenticationFilter.class) public interface SystemApi { @Named("system:version") @Path("/version") @Consumes(MediaType.APPLICATION_JSON) @GET
Version version();
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryHttpApiModule.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/handlers/ArtifactoryErrorHandler.java // public class ArtifactoryErrorHandler implements HttpErrorHandler { // @Resource // protected Logger logger = Logger.NULL; // // @Override // public void handleError(HttpCommand command, HttpResponse response) { // // // it is important to always read fully and close streams // String message = parseMessage(response); // // Exception exception = message != null ? new HttpResponseException(command, response, message) // : new HttpResponseException(command, response); // try { // message = message != null ? message // : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), response.getStatusLine()); // switch (response.getStatusCode()) { // case 400: // if (command.getCurrentRequest().getMethod().equals("POST")) { // if (command.getCurrentRequest().getEndpoint().getPath().endsWith("/aql")) { // if (message.indexOf("Fail to parse query") != -1) { // exception = new IllegalArgumentException(message, exception); // } // } else if (command.getCurrentRequest().getEndpoint().getPath().startsWith("/api/build/promote")) { // exception = new IllegalArgumentException(message, exception); // } // } // break; // case 401: // exception = new AuthorizationException(message, exception); // break; // case 404: // exception = new ResourceNotFoundException(message, exception); // break; // case 409: // exception = new ResourceAlreadyExistsException(message, exception); // break; // } // } finally { // closeQuietly(response.getPayload()); // command.setException(exception); // } // } // // public String parseMessage(HttpResponse response) { // if (response.getPayload() == null) // return null; // try { // return Strings2.toStringAndClose(response.getPayload().openStream()); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // }
import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; import org.jclouds.rest.ConfiguresHttpApi; import org.jclouds.rest.config.HttpApiModule; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.handlers.ArtifactoryErrorHandler;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.config; /** * Configures the Artifactory connection. */ @ConfiguresHttpApi public class ArtifactoryHttpApiModule extends HttpApiModule<ArtifactoryApi> { @Override protected void bindErrorHandlers() {
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/handlers/ArtifactoryErrorHandler.java // public class ArtifactoryErrorHandler implements HttpErrorHandler { // @Resource // protected Logger logger = Logger.NULL; // // @Override // public void handleError(HttpCommand command, HttpResponse response) { // // // it is important to always read fully and close streams // String message = parseMessage(response); // // Exception exception = message != null ? new HttpResponseException(command, response, message) // : new HttpResponseException(command, response); // try { // message = message != null ? message // : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), response.getStatusLine()); // switch (response.getStatusCode()) { // case 400: // if (command.getCurrentRequest().getMethod().equals("POST")) { // if (command.getCurrentRequest().getEndpoint().getPath().endsWith("/aql")) { // if (message.indexOf("Fail to parse query") != -1) { // exception = new IllegalArgumentException(message, exception); // } // } else if (command.getCurrentRequest().getEndpoint().getPath().startsWith("/api/build/promote")) { // exception = new IllegalArgumentException(message, exception); // } // } // break; // case 401: // exception = new AuthorizationException(message, exception); // break; // case 404: // exception = new ResourceNotFoundException(message, exception); // break; // case 409: // exception = new ResourceAlreadyExistsException(message, exception); // break; // } // } finally { // closeQuietly(response.getPayload()); // command.setException(exception); // } // } // // public String parseMessage(HttpResponse response) { // if (response.getPayload() == null) // return null; // try { // return Strings2.toStringAndClose(response.getPayload().openStream()); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // } // Path: src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryHttpApiModule.java import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; import org.jclouds.rest.ConfiguresHttpApi; import org.jclouds.rest.config.HttpApiModule; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.handlers.ArtifactoryErrorHandler; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.config; /** * Configures the Artifactory connection. */ @ConfiguresHttpApi public class ArtifactoryHttpApiModule extends HttpApiModule<ArtifactoryApi> { @Override protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ArtifactoryErrorHandler.class);
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token";
import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable;
} } return null; } /** * Find endpoint searching first within `System Properties` and * then within `Environment Variables` returning whichever has a * value first. * * @return endpoint or null if it can't be found. */ public static String inferEndpoint() { final String possibleValue = ArtifactoryUtils .retriveExternalValue(ENDPOINT_SYSTEM_PROPERTY, ENDPOINT_ENVIRONMENT_VARIABLE); return possibleValue != null ? possibleValue : DEFAULT_ENDPOINT; } /** * Find credentials (Basic, Token, or Anonymous) from system/environment. * * @return ArtifactoryCredentials */ public static ArtifactoryAuthentication inferAuthentication() { // 1.) Check for "Basic" auth credentials. final ArtifactoryAuthentication.Builder inferAuth = ArtifactoryAuthentication.builder(); String authValue = ArtifactoryUtils
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token"; // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable; } } return null; } /** * Find endpoint searching first within `System Properties` and * then within `Environment Variables` returning whichever has a * value first. * * @return endpoint or null if it can't be found. */ public static String inferEndpoint() { final String possibleValue = ArtifactoryUtils .retriveExternalValue(ENDPOINT_SYSTEM_PROPERTY, ENDPOINT_ENVIRONMENT_VARIABLE); return possibleValue != null ? possibleValue : DEFAULT_ENDPOINT; } /** * Find credentials (Basic, Token, or Anonymous) from system/environment. * * @return ArtifactoryCredentials */ public static ArtifactoryAuthentication inferAuthentication() { // 1.) Check for "Basic" auth credentials. final ArtifactoryAuthentication.Builder inferAuth = ArtifactoryAuthentication.builder(); String authValue = ArtifactoryUtils
.retriveExternalValue(CREDENTIALS_SYSTEM_PROPERTY,
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token";
import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable;
} return null; } /** * Find endpoint searching first within `System Properties` and * then within `Environment Variables` returning whichever has a * value first. * * @return endpoint or null if it can't be found. */ public static String inferEndpoint() { final String possibleValue = ArtifactoryUtils .retriveExternalValue(ENDPOINT_SYSTEM_PROPERTY, ENDPOINT_ENVIRONMENT_VARIABLE); return possibleValue != null ? possibleValue : DEFAULT_ENDPOINT; } /** * Find credentials (Basic, Token, or Anonymous) from system/environment. * * @return ArtifactoryCredentials */ public static ArtifactoryAuthentication inferAuthentication() { // 1.) Check for "Basic" auth credentials. final ArtifactoryAuthentication.Builder inferAuth = ArtifactoryAuthentication.builder(); String authValue = ArtifactoryUtils .retriveExternalValue(CREDENTIALS_SYSTEM_PROPERTY,
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token"; // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable; } return null; } /** * Find endpoint searching first within `System Properties` and * then within `Environment Variables` returning whichever has a * value first. * * @return endpoint or null if it can't be found. */ public static String inferEndpoint() { final String possibleValue = ArtifactoryUtils .retriveExternalValue(ENDPOINT_SYSTEM_PROPERTY, ENDPOINT_ENVIRONMENT_VARIABLE); return possibleValue != null ? possibleValue : DEFAULT_ENDPOINT; } /** * Find credentials (Basic, Token, or Anonymous) from system/environment. * * @return ArtifactoryCredentials */ public static ArtifactoryAuthentication inferAuthentication() { // 1.) Check for "Basic" auth credentials. final ArtifactoryAuthentication.Builder inferAuth = ArtifactoryAuthentication.builder(); String authValue = ArtifactoryUtils .retriveExternalValue(CREDENTIALS_SYSTEM_PROPERTY,
CREDENTIALS_ENVIRONMENT_VARIABLE);
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token";
import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable;
* then within `Environment Variables` returning whichever has a * value first. * * @return endpoint or null if it can't be found. */ public static String inferEndpoint() { final String possibleValue = ArtifactoryUtils .retriveExternalValue(ENDPOINT_SYSTEM_PROPERTY, ENDPOINT_ENVIRONMENT_VARIABLE); return possibleValue != null ? possibleValue : DEFAULT_ENDPOINT; } /** * Find credentials (Basic, Token, or Anonymous) from system/environment. * * @return ArtifactoryCredentials */ public static ArtifactoryAuthentication inferAuthentication() { // 1.) Check for "Basic" auth credentials. final ArtifactoryAuthentication.Builder inferAuth = ArtifactoryAuthentication.builder(); String authValue = ArtifactoryUtils .retriveExternalValue(CREDENTIALS_SYSTEM_PROPERTY, CREDENTIALS_ENVIRONMENT_VARIABLE); if (authValue != null) { inferAuth.credentials(authValue); } else { // 2.) Check for "Bearer" auth token. authValue = ArtifactoryUtils
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token"; // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable; * then within `Environment Variables` returning whichever has a * value first. * * @return endpoint or null if it can't be found. */ public static String inferEndpoint() { final String possibleValue = ArtifactoryUtils .retriveExternalValue(ENDPOINT_SYSTEM_PROPERTY, ENDPOINT_ENVIRONMENT_VARIABLE); return possibleValue != null ? possibleValue : DEFAULT_ENDPOINT; } /** * Find credentials (Basic, Token, or Anonymous) from system/environment. * * @return ArtifactoryCredentials */ public static ArtifactoryAuthentication inferAuthentication() { // 1.) Check for "Basic" auth credentials. final ArtifactoryAuthentication.Builder inferAuth = ArtifactoryAuthentication.builder(); String authValue = ArtifactoryUtils .retriveExternalValue(CREDENTIALS_SYSTEM_PROPERTY, CREDENTIALS_ENVIRONMENT_VARIABLE); if (authValue != null) { inferAuth.credentials(authValue); } else { // 2.) Check for "Bearer" auth token. authValue = ArtifactoryUtils
.retriveExternalValue(TOKEN_SYSTEM_PROPERTY,
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token";
import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable;
* value first. * * @return endpoint or null if it can't be found. */ public static String inferEndpoint() { final String possibleValue = ArtifactoryUtils .retriveExternalValue(ENDPOINT_SYSTEM_PROPERTY, ENDPOINT_ENVIRONMENT_VARIABLE); return possibleValue != null ? possibleValue : DEFAULT_ENDPOINT; } /** * Find credentials (Basic, Token, or Anonymous) from system/environment. * * @return ArtifactoryCredentials */ public static ArtifactoryAuthentication inferAuthentication() { // 1.) Check for "Basic" auth credentials. final ArtifactoryAuthentication.Builder inferAuth = ArtifactoryAuthentication.builder(); String authValue = ArtifactoryUtils .retriveExternalValue(CREDENTIALS_SYSTEM_PROPERTY, CREDENTIALS_ENVIRONMENT_VARIABLE); if (authValue != null) { inferAuth.credentials(authValue); } else { // 2.) Check for "Bearer" auth token. authValue = ArtifactoryUtils .retriveExternalValue(TOKEN_SYSTEM_PROPERTY,
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token"; // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable; * value first. * * @return endpoint or null if it can't be found. */ public static String inferEndpoint() { final String possibleValue = ArtifactoryUtils .retriveExternalValue(ENDPOINT_SYSTEM_PROPERTY, ENDPOINT_ENVIRONMENT_VARIABLE); return possibleValue != null ? possibleValue : DEFAULT_ENDPOINT; } /** * Find credentials (Basic, Token, or Anonymous) from system/environment. * * @return ArtifactoryCredentials */ public static ArtifactoryAuthentication inferAuthentication() { // 1.) Check for "Basic" auth credentials. final ArtifactoryAuthentication.Builder inferAuth = ArtifactoryAuthentication.builder(); String authValue = ArtifactoryUtils .retriveExternalValue(CREDENTIALS_SYSTEM_PROPERTY, CREDENTIALS_ENVIRONMENT_VARIABLE); if (authValue != null) { inferAuth.credentials(authValue); } else { // 2.) Check for "Bearer" auth token. authValue = ArtifactoryUtils .retriveExternalValue(TOKEN_SYSTEM_PROPERTY,
TOKEN_ENVIRONMENT_VARIABLE);
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token";
import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable;
inferAuth.credentials(authValue); } else { // 2.) Check for "Bearer" auth token. authValue = ArtifactoryUtils .retriveExternalValue(TOKEN_SYSTEM_PROPERTY, TOKEN_ENVIRONMENT_VARIABLE); if (authValue != null) { inferAuth.token(authValue); } } // 3.) If neither #1 or #2 find anything "Anonymous" access is assumed. return inferAuth.build(); } /** * Find jclouds overrides (e.g. Properties) first searching within System * Properties and then within Environment Variables (former takes precedance). * * @return Properties object with populated jclouds properties. */ public static Properties inferOverrides() { final Properties overrides = new Properties(); // 1.) Iterate over system properties looking for relevant properties. final Properties systemProperties = System.getProperties(); final Enumeration<String> enums = (Enumeration<String>) systemProperties.propertyNames(); while (enums.hasMoreElements()) { final String key = enums.nextElement();
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token"; // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable; inferAuth.credentials(authValue); } else { // 2.) Check for "Bearer" auth token. authValue = ArtifactoryUtils .retriveExternalValue(TOKEN_SYSTEM_PROPERTY, TOKEN_ENVIRONMENT_VARIABLE); if (authValue != null) { inferAuth.token(authValue); } } // 3.) If neither #1 or #2 find anything "Anonymous" access is assumed. return inferAuth.build(); } /** * Find jclouds overrides (e.g. Properties) first searching within System * Properties and then within Environment Variables (former takes precedance). * * @return Properties object with populated jclouds properties. */ public static Properties inferOverrides() { final Properties overrides = new Properties(); // 1.) Iterate over system properties looking for relevant properties. final Properties systemProperties = System.getProperties(); final Enumeration<String> enums = (Enumeration<String>) systemProperties.propertyNames(); while (enums.hasMoreElements()) { final String key = enums.nextElement();
if (key.startsWith(ARTIFACTORY_REST_PROPERTY_ID)) {
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token";
import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable;
} else { // 2.) Check for "Bearer" auth token. authValue = ArtifactoryUtils .retriveExternalValue(TOKEN_SYSTEM_PROPERTY, TOKEN_ENVIRONMENT_VARIABLE); if (authValue != null) { inferAuth.token(authValue); } } // 3.) If neither #1 or #2 find anything "Anonymous" access is assumed. return inferAuth.build(); } /** * Find jclouds overrides (e.g. Properties) first searching within System * Properties and then within Environment Variables (former takes precedance). * * @return Properties object with populated jclouds properties. */ public static Properties inferOverrides() { final Properties overrides = new Properties(); // 1.) Iterate over system properties looking for relevant properties. final Properties systemProperties = System.getProperties(); final Enumeration<String> enums = (Enumeration<String>) systemProperties.propertyNames(); while (enums.hasMoreElements()) { final String key = enums.nextElement(); if (key.startsWith(ARTIFACTORY_REST_PROPERTY_ID)) {
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token"; // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable; } else { // 2.) Check for "Bearer" auth token. authValue = ArtifactoryUtils .retriveExternalValue(TOKEN_SYSTEM_PROPERTY, TOKEN_ENVIRONMENT_VARIABLE); if (authValue != null) { inferAuth.token(authValue); } } // 3.) If neither #1 or #2 find anything "Anonymous" access is assumed. return inferAuth.build(); } /** * Find jclouds overrides (e.g. Properties) first searching within System * Properties and then within Environment Variables (former takes precedance). * * @return Properties object with populated jclouds properties. */ public static Properties inferOverrides() { final Properties overrides = new Properties(); // 1.) Iterate over system properties looking for relevant properties. final Properties systemProperties = System.getProperties(); final Enumeration<String> enums = (Enumeration<String>) systemProperties.propertyNames(); while (enums.hasMoreElements()) { final String key = enums.nextElement(); if (key.startsWith(ARTIFACTORY_REST_PROPERTY_ID)) {
final int index = key.indexOf(JCLOUDS_PROPERTY_ID);
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token";
import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable;
// 3.) If neither #1 or #2 find anything "Anonymous" access is assumed. return inferAuth.build(); } /** * Find jclouds overrides (e.g. Properties) first searching within System * Properties and then within Environment Variables (former takes precedance). * * @return Properties object with populated jclouds properties. */ public static Properties inferOverrides() { final Properties overrides = new Properties(); // 1.) Iterate over system properties looking for relevant properties. final Properties systemProperties = System.getProperties(); final Enumeration<String> enums = (Enumeration<String>) systemProperties.propertyNames(); while (enums.hasMoreElements()) { final String key = enums.nextElement(); if (key.startsWith(ARTIFACTORY_REST_PROPERTY_ID)) { final int index = key.indexOf(JCLOUDS_PROPERTY_ID); final String trimmedKey = key.substring(index, key.length()); overrides.put(trimmedKey, systemProperties.getProperty(key)); } } // 2.) Iterate over environment variables looking for relevant variables. System // Properties take precedence here so if the same property was already found // there then we don't add it or attempt to override. for (final Map.Entry<String, String> entry : System.getenv().entrySet()) {
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token"; // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable; // 3.) If neither #1 or #2 find anything "Anonymous" access is assumed. return inferAuth.build(); } /** * Find jclouds overrides (e.g. Properties) first searching within System * Properties and then within Environment Variables (former takes precedance). * * @return Properties object with populated jclouds properties. */ public static Properties inferOverrides() { final Properties overrides = new Properties(); // 1.) Iterate over system properties looking for relevant properties. final Properties systemProperties = System.getProperties(); final Enumeration<String> enums = (Enumeration<String>) systemProperties.propertyNames(); while (enums.hasMoreElements()) { final String key = enums.nextElement(); if (key.startsWith(ARTIFACTORY_REST_PROPERTY_ID)) { final int index = key.indexOf(JCLOUDS_PROPERTY_ID); final String trimmedKey = key.substring(index, key.length()); overrides.put(trimmedKey, systemProperties.getProperty(key)); } } // 2.) Iterate over environment variables looking for relevant variables. System // Properties take precedence here so if the same property was already found // there then we don't add it or attempt to override. for (final Map.Entry<String, String> entry : System.getenv().entrySet()) {
if (entry.getKey().startsWith(ARTIFACTORY_REST_VARIABLE_ID)) {
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token";
import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable;
// 3.) If neither #1 or #2 find anything "Anonymous" access is assumed. return inferAuth.build(); } /** * Find jclouds overrides (e.g. Properties) first searching within System * Properties and then within Environment Variables (former takes precedance). * * @return Properties object with populated jclouds properties. */ public static Properties inferOverrides() { final Properties overrides = new Properties(); // 1.) Iterate over system properties looking for relevant properties. final Properties systemProperties = System.getProperties(); final Enumeration<String> enums = (Enumeration<String>) systemProperties.propertyNames(); while (enums.hasMoreElements()) { final String key = enums.nextElement(); if (key.startsWith(ARTIFACTORY_REST_PROPERTY_ID)) { final int index = key.indexOf(JCLOUDS_PROPERTY_ID); final String trimmedKey = key.substring(index, key.length()); overrides.put(trimmedKey, systemProperties.getProperty(key)); } } // 2.) Iterate over environment variables looking for relevant variables. System // Properties take precedence here so if the same property was already found // there then we don't add it or attempt to override. for (final Map.Entry<String, String> entry : System.getenv().entrySet()) { if (entry.getKey().startsWith(ARTIFACTORY_REST_VARIABLE_ID)) {
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_PROPERTY_ID = "artifactory.rest." + JCLOUDS_PROPERTY_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ARTIFACTORY_REST_VARIABLE_ID = "ARTIFACTORY_REST_" + JCLOUDS_VARIABLE_ID; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String CREDENTIALS_SYSTEM_PROPERTY = "artifactory.rest.credentials"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:8080/artifactory"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String ENDPOINT_SYSTEM_PROPERTY = "artifactory.rest.endpoint"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_PROPERTY_ID = "jclouds."; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_ENVIRONMENT_VARIABLE = TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryConstants.java // public static final String TOKEN_SYSTEM_PROPERTY = "artifactory.rest.token"; // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryUtils.java import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ARTIFACTORY_REST_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.CREDENTIALS_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.DEFAULT_ENDPOINT; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.ENDPOINT_SYSTEM_PROPERTY; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_PROPERTY_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.JCLOUDS_VARIABLE_ID; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_ENVIRONMENT_VARIABLE; import static com.cdancy.artifactory.rest.ArtifactoryConstants.TOKEN_SYSTEM_PROPERTY; import com.google.common.base.Joiner; import com.google.common.base.Throwables; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Objects; import java.util.Properties; import org.jclouds.javax.annotation.Nullable; // 3.) If neither #1 or #2 find anything "Anonymous" access is assumed. return inferAuth.build(); } /** * Find jclouds overrides (e.g. Properties) first searching within System * Properties and then within Environment Variables (former takes precedance). * * @return Properties object with populated jclouds properties. */ public static Properties inferOverrides() { final Properties overrides = new Properties(); // 1.) Iterate over system properties looking for relevant properties. final Properties systemProperties = System.getProperties(); final Enumeration<String> enums = (Enumeration<String>) systemProperties.propertyNames(); while (enums.hasMoreElements()) { final String key = enums.nextElement(); if (key.startsWith(ARTIFACTORY_REST_PROPERTY_ID)) { final int index = key.indexOf(JCLOUDS_PROPERTY_ID); final String trimmedKey = key.substring(index, key.length()); overrides.put(trimmedKey, systemProperties.getProperty(key)); } } // 2.) Iterate over environment variables looking for relevant variables. System // Properties take precedence here so if the same property was already found // there then we don't add it or attempt to override. for (final Map.Entry<String, String> entry : System.getenv().entrySet()) { if (entry.getKey().startsWith(ARTIFACTORY_REST_VARIABLE_ID)) {
final int index = entry.getKey().indexOf(JCLOUDS_VARIABLE_ID);
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/DockerApiMockTest.java
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertFalse(boolean value) { // assertThat(value).isFalse(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/docker/PromoteImage.java // @AutoValue // public abstract class PromoteImage { // // public abstract String targetRepo(); // // public abstract String dockerRepository(); // // @Nullable // public abstract String tag(); // // @Nullable // public abstract String targetTag(); // // public abstract boolean copy(); // // PromoteImage() { // } // // @SerializedNames({ "targetRepo", "dockerRepository", "tag", "targetTag", "copy" }) // public static PromoteImage create(String targetRepo, String dockerRepository, String tag, String targetTag, boolean copy) { // return new AutoValue_PromoteImage(targetRepo, dockerRepository, tag, targetTag, copy); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // }
import static com.cdancy.artifactory.rest.TestUtilities.assertFalse; import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.docker.PromoteImage; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import org.testng.annotations.Test; import javax.ws.rs.core.MediaType; import java.util.List;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link DockerApi} * class. */ @Test(groups = "unit", testName = "DockerApiMockTest") public class DockerApiMockTest extends BaseArtifactoryMockTest { public void testPromote() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); String payload = payloadFromResource("/docker-promote.json"); server.enqueue(new MockResponse().setBody(payload).setResponseCode(200));
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertFalse(boolean value) { // assertThat(value).isFalse(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/docker/PromoteImage.java // @AutoValue // public abstract class PromoteImage { // // public abstract String targetRepo(); // // public abstract String dockerRepository(); // // @Nullable // public abstract String tag(); // // @Nullable // public abstract String targetTag(); // // public abstract boolean copy(); // // PromoteImage() { // } // // @SerializedNames({ "targetRepo", "dockerRepository", "tag", "targetTag", "copy" }) // public static PromoteImage create(String targetRepo, String dockerRepository, String tag, String targetTag, boolean copy) { // return new AutoValue_PromoteImage(targetRepo, dockerRepository, tag, targetTag, copy); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/DockerApiMockTest.java import static com.cdancy.artifactory.rest.TestUtilities.assertFalse; import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.docker.PromoteImage; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import org.testng.annotations.Test; import javax.ws.rs.core.MediaType; import java.util.List; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link DockerApi} * class. */ @Test(groups = "unit", testName = "DockerApiMockTest") public class DockerApiMockTest extends BaseArtifactoryMockTest { public void testPromote() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); String payload = payloadFromResource("/docker-promote.json"); server.enqueue(new MockResponse().setBody(payload).setResponseCode(200));
ArtifactoryApi jcloudsApi = api(server.getUrl("/"));
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/DockerApiMockTest.java
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertFalse(boolean value) { // assertThat(value).isFalse(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/docker/PromoteImage.java // @AutoValue // public abstract class PromoteImage { // // public abstract String targetRepo(); // // public abstract String dockerRepository(); // // @Nullable // public abstract String tag(); // // @Nullable // public abstract String targetTag(); // // public abstract boolean copy(); // // PromoteImage() { // } // // @SerializedNames({ "targetRepo", "dockerRepository", "tag", "targetTag", "copy" }) // public static PromoteImage create(String targetRepo, String dockerRepository, String tag, String targetTag, boolean copy) { // return new AutoValue_PromoteImage(targetRepo, dockerRepository, tag, targetTag, copy); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // }
import static com.cdancy.artifactory.rest.TestUtilities.assertFalse; import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.docker.PromoteImage; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import org.testng.annotations.Test; import javax.ws.rs.core.MediaType; import java.util.List;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link DockerApi} * class. */ @Test(groups = "unit", testName = "DockerApiMockTest") public class DockerApiMockTest extends BaseArtifactoryMockTest { public void testPromote() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); String payload = payloadFromResource("/docker-promote.json"); server.enqueue(new MockResponse().setBody(payload).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); DockerApi api = jcloudsApi.dockerApi(); try {
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertFalse(boolean value) { // assertThat(value).isFalse(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/docker/PromoteImage.java // @AutoValue // public abstract class PromoteImage { // // public abstract String targetRepo(); // // public abstract String dockerRepository(); // // @Nullable // public abstract String tag(); // // @Nullable // public abstract String targetTag(); // // public abstract boolean copy(); // // PromoteImage() { // } // // @SerializedNames({ "targetRepo", "dockerRepository", "tag", "targetTag", "copy" }) // public static PromoteImage create(String targetRepo, String dockerRepository, String tag, String targetTag, boolean copy) { // return new AutoValue_PromoteImage(targetRepo, dockerRepository, tag, targetTag, copy); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/DockerApiMockTest.java import static com.cdancy.artifactory.rest.TestUtilities.assertFalse; import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.docker.PromoteImage; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import org.testng.annotations.Test; import javax.ws.rs.core.MediaType; import java.util.List; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link DockerApi} * class. */ @Test(groups = "unit", testName = "DockerApiMockTest") public class DockerApiMockTest extends BaseArtifactoryMockTest { public void testPromote() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); String payload = payloadFromResource("/docker-promote.json"); server.enqueue(new MockResponse().setBody(payload).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); DockerApi api = jcloudsApi.dockerApi(); try {
PromoteImage dockerPromote = PromoteImage.create("docker-promoted", "library/artifactory", "1.0.0","latest", false);
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/DockerApiMockTest.java
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertFalse(boolean value) { // assertThat(value).isFalse(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/docker/PromoteImage.java // @AutoValue // public abstract class PromoteImage { // // public abstract String targetRepo(); // // public abstract String dockerRepository(); // // @Nullable // public abstract String tag(); // // @Nullable // public abstract String targetTag(); // // public abstract boolean copy(); // // PromoteImage() { // } // // @SerializedNames({ "targetRepo", "dockerRepository", "tag", "targetTag", "copy" }) // public static PromoteImage create(String targetRepo, String dockerRepository, String tag, String targetTag, boolean copy) { // return new AutoValue_PromoteImage(targetRepo, dockerRepository, tag, targetTag, copy); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // }
import static com.cdancy.artifactory.rest.TestUtilities.assertFalse; import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.docker.PromoteImage; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import org.testng.annotations.Test; import javax.ws.rs.core.MediaType; import java.util.List;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link DockerApi} * class. */ @Test(groups = "unit", testName = "DockerApiMockTest") public class DockerApiMockTest extends BaseArtifactoryMockTest { public void testPromote() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); String payload = payloadFromResource("/docker-promote.json"); server.enqueue(new MockResponse().setBody(payload).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); DockerApi api = jcloudsApi.dockerApi(); try { PromoteImage dockerPromote = PromoteImage.create("docker-promoted", "library/artifactory", "1.0.0","latest", false); boolean success = api.promote("docker-local", dockerPromote);
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertFalse(boolean value) { // assertThat(value).isFalse(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/docker/PromoteImage.java // @AutoValue // public abstract class PromoteImage { // // public abstract String targetRepo(); // // public abstract String dockerRepository(); // // @Nullable // public abstract String tag(); // // @Nullable // public abstract String targetTag(); // // public abstract boolean copy(); // // PromoteImage() { // } // // @SerializedNames({ "targetRepo", "dockerRepository", "tag", "targetTag", "copy" }) // public static PromoteImage create(String targetRepo, String dockerRepository, String tag, String targetTag, boolean copy) { // return new AutoValue_PromoteImage(targetRepo, dockerRepository, tag, targetTag, copy); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/DockerApiMockTest.java import static com.cdancy.artifactory.rest.TestUtilities.assertFalse; import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.docker.PromoteImage; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import org.testng.annotations.Test; import javax.ws.rs.core.MediaType; import java.util.List; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link DockerApi} * class. */ @Test(groups = "unit", testName = "DockerApiMockTest") public class DockerApiMockTest extends BaseArtifactoryMockTest { public void testPromote() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); String payload = payloadFromResource("/docker-promote.json"); server.enqueue(new MockResponse().setBody(payload).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); DockerApi api = jcloudsApi.dockerApi(); try { PromoteImage dockerPromote = PromoteImage.create("docker-promoted", "library/artifactory", "1.0.0","latest", false); boolean success = api.promote("docker-local", dockerPromote);
assertTrue(success);
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/DockerApiMockTest.java
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertFalse(boolean value) { // assertThat(value).isFalse(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/docker/PromoteImage.java // @AutoValue // public abstract class PromoteImage { // // public abstract String targetRepo(); // // public abstract String dockerRepository(); // // @Nullable // public abstract String tag(); // // @Nullable // public abstract String targetTag(); // // public abstract boolean copy(); // // PromoteImage() { // } // // @SerializedNames({ "targetRepo", "dockerRepository", "tag", "targetTag", "copy" }) // public static PromoteImage create(String targetRepo, String dockerRepository, String tag, String targetTag, boolean copy) { // return new AutoValue_PromoteImage(targetRepo, dockerRepository, tag, targetTag, copy); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // }
import static com.cdancy.artifactory.rest.TestUtilities.assertFalse; import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.docker.PromoteImage; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import org.testng.annotations.Test; import javax.ws.rs.core.MediaType; import java.util.List;
} } public void testPromoteNonExistentImage() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); String payload = "Unable to find tag file at 'repositories/library/artifactory/latest/tag.json'"; server.enqueue(new MockResponse().setBody(payload).setResponseCode(404)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); DockerApi api = jcloudsApi.dockerApi(); try { PromoteImage dockerPromote = PromoteImage.create("docker-promoted", "library/artifactory", "latest", null, false); boolean success = api.promote("docker-local", dockerPromote); assertFalse(success); assertSent(server, "POST", "/api/docker/docker-local/v2/promote", MediaType.TEXT_PLAIN); } finally { jcloudsApi.close(); server.shutdown(); } } public void testListRepositories() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); String payload = payloadFromResource("/docker-list-repositories.json"); server.enqueue(new MockResponse().setBody(payload).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); DockerApi api = jcloudsApi.dockerApi(); try { List<String> repos = api.repositories("docker-local");
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertFalse(boolean value) { // assertThat(value).isFalse(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/docker/PromoteImage.java // @AutoValue // public abstract class PromoteImage { // // public abstract String targetRepo(); // // public abstract String dockerRepository(); // // @Nullable // public abstract String tag(); // // @Nullable // public abstract String targetTag(); // // public abstract boolean copy(); // // PromoteImage() { // } // // @SerializedNames({ "targetRepo", "dockerRepository", "tag", "targetTag", "copy" }) // public static PromoteImage create(String targetRepo, String dockerRepository, String tag, String targetTag, boolean copy) { // return new AutoValue_PromoteImage(targetRepo, dockerRepository, tag, targetTag, copy); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/DockerApiMockTest.java import static com.cdancy.artifactory.rest.TestUtilities.assertFalse; import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.docker.PromoteImage; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import org.testng.annotations.Test; import javax.ws.rs.core.MediaType; import java.util.List; } } public void testPromoteNonExistentImage() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); String payload = "Unable to find tag file at 'repositories/library/artifactory/latest/tag.json'"; server.enqueue(new MockResponse().setBody(payload).setResponseCode(404)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); DockerApi api = jcloudsApi.dockerApi(); try { PromoteImage dockerPromote = PromoteImage.create("docker-promoted", "library/artifactory", "latest", null, false); boolean success = api.promote("docker-local", dockerPromote); assertFalse(success); assertSent(server, "POST", "/api/docker/docker-local/v2/promote", MediaType.TEXT_PLAIN); } finally { jcloudsApi.close(); server.shutdown(); } } public void testListRepositories() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); String payload = payloadFromResource("/docker-list-repositories.json"); server.enqueue(new MockResponse().setBody(payload).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); DockerApi api = jcloudsApi.dockerApi(); try { List<String> repos = api.repositories("docker-local");
assertNotNull(repos);
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/ArtifactoryClient.java
// Path: src/main/java/com/cdancy/artifactory/rest/auth/AuthenticationType.java // public enum AuthenticationType { // // Basic("Basic"), // Bearer("Bearer"), // Anonymous(""); // // private final String type; // // private AuthenticationType(final String type) { // this.type = type; // } // // @Override // public String toString() { // return type; // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryAuthenticationModule.java // public class ArtifactoryAuthenticationModule extends AbstractModule { // // private final ArtifactoryAuthentication authentication; // // public ArtifactoryAuthenticationModule(final ArtifactoryAuthentication authentication) { // this.authentication = Objects.requireNonNull(authentication); // } // // @Override // protected void configure() { // bind(ArtifactoryAuthentication.class).toProvider(new ArtifactoryAuthenticationProvider(authentication)); // } // }
import com.cdancy.artifactory.rest.auth.AuthenticationType; import com.cdancy.artifactory.rest.config.ArtifactoryAuthenticationModule; import com.google.common.collect.Lists; import java.util.Properties; import java.io.Closeable; import java.io.IOException; import org.jclouds.ContextBuilder; import org.jclouds.javax.annotation.Nullable;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest; public final class ArtifactoryClient implements Closeable { private final String endPoint; private final ArtifactoryAuthentication credentials; private final ArtifactoryApi artifactoryApi; private final Properties overrides; /** * Create a ArtifactoryClient inferring endpoint and authentication from * environment and system properties. */ public ArtifactoryClient() { this(null, null, null); } /** * Create an ArtifactoryClient. If any of the passed in variables are null we * will query System Properties and Environment Variables, in order, to * search for values that may be set in a devops/CI fashion. The only * difference is the `overrides` which gets merged, but takes precedence, * with those System Properties and Environment Variables found. * * @param endPoint URL of Artifactory instance. * @param authentication authentication used to connect to Artifactory instance. * @param overrides jclouds Properties to override defaults when creating a new ArtifactoryApi. */ public ArtifactoryClient(@Nullable final String endPoint, @Nullable final ArtifactoryAuthentication authentication, @Nullable final Properties overrides) { this.endPoint = endPoint != null ? endPoint : ArtifactoryUtils.inferEndpoint(); this.credentials = authentication != null ? authentication : ArtifactoryUtils.inferAuthentication(); this.overrides = mergeOverrides(overrides); this.artifactoryApi = createApi(this.endPoint, this.credentials, this.overrides); } private ArtifactoryApi createApi(final String endPoint, final ArtifactoryAuthentication authentication, final Properties overrides) { return ContextBuilder .newBuilder(new ArtifactoryApiMetadata.Builder().build()) .endpoint(endPoint)
// Path: src/main/java/com/cdancy/artifactory/rest/auth/AuthenticationType.java // public enum AuthenticationType { // // Basic("Basic"), // Bearer("Bearer"), // Anonymous(""); // // private final String type; // // private AuthenticationType(final String type) { // this.type = type; // } // // @Override // public String toString() { // return type; // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryAuthenticationModule.java // public class ArtifactoryAuthenticationModule extends AbstractModule { // // private final ArtifactoryAuthentication authentication; // // public ArtifactoryAuthenticationModule(final ArtifactoryAuthentication authentication) { // this.authentication = Objects.requireNonNull(authentication); // } // // @Override // protected void configure() { // bind(ArtifactoryAuthentication.class).toProvider(new ArtifactoryAuthenticationProvider(authentication)); // } // } // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryClient.java import com.cdancy.artifactory.rest.auth.AuthenticationType; import com.cdancy.artifactory.rest.config.ArtifactoryAuthenticationModule; import com.google.common.collect.Lists; import java.util.Properties; import java.io.Closeable; import java.io.IOException; import org.jclouds.ContextBuilder; import org.jclouds.javax.annotation.Nullable; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest; public final class ArtifactoryClient implements Closeable { private final String endPoint; private final ArtifactoryAuthentication credentials; private final ArtifactoryApi artifactoryApi; private final Properties overrides; /** * Create a ArtifactoryClient inferring endpoint and authentication from * environment and system properties. */ public ArtifactoryClient() { this(null, null, null); } /** * Create an ArtifactoryClient. If any of the passed in variables are null we * will query System Properties and Environment Variables, in order, to * search for values that may be set in a devops/CI fashion. The only * difference is the `overrides` which gets merged, but takes precedence, * with those System Properties and Environment Variables found. * * @param endPoint URL of Artifactory instance. * @param authentication authentication used to connect to Artifactory instance. * @param overrides jclouds Properties to override defaults when creating a new ArtifactoryApi. */ public ArtifactoryClient(@Nullable final String endPoint, @Nullable final ArtifactoryAuthentication authentication, @Nullable final Properties overrides) { this.endPoint = endPoint != null ? endPoint : ArtifactoryUtils.inferEndpoint(); this.credentials = authentication != null ? authentication : ArtifactoryUtils.inferAuthentication(); this.overrides = mergeOverrides(overrides); this.artifactoryApi = createApi(this.endPoint, this.credentials, this.overrides); } private ArtifactoryApi createApi(final String endPoint, final ArtifactoryAuthentication authentication, final Properties overrides) { return ContextBuilder .newBuilder(new ArtifactoryApiMetadata.Builder().build()) .endpoint(endPoint)
.modules(Lists.newArrayList(new ArtifactoryAuthenticationModule(authentication)))
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/ArtifactoryClient.java
// Path: src/main/java/com/cdancy/artifactory/rest/auth/AuthenticationType.java // public enum AuthenticationType { // // Basic("Basic"), // Bearer("Bearer"), // Anonymous(""); // // private final String type; // // private AuthenticationType(final String type) { // this.type = type; // } // // @Override // public String toString() { // return type; // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryAuthenticationModule.java // public class ArtifactoryAuthenticationModule extends AbstractModule { // // private final ArtifactoryAuthentication authentication; // // public ArtifactoryAuthenticationModule(final ArtifactoryAuthentication authentication) { // this.authentication = Objects.requireNonNull(authentication); // } // // @Override // protected void configure() { // bind(ArtifactoryAuthentication.class).toProvider(new ArtifactoryAuthenticationProvider(authentication)); // } // }
import com.cdancy.artifactory.rest.auth.AuthenticationType; import com.cdancy.artifactory.rest.config.ArtifactoryAuthenticationModule; import com.google.common.collect.Lists; import java.util.Properties; import java.io.Closeable; import java.io.IOException; import org.jclouds.ContextBuilder; import org.jclouds.javax.annotation.Nullable;
* the potentially passed in overrides with those. * * @param possibleOverrides Optional passed in overrides. * @return Properties object. */ private Properties mergeOverrides(final Properties possibleOverrides) { final Properties inferOverrides = ArtifactoryUtils.inferOverrides(); if (possibleOverrides != null) { inferOverrides.putAll(possibleOverrides); } return inferOverrides; } public String endPoint() { return this.endPoint; } @Deprecated public String credentials() { return this.authValue(); } public Properties overrides() { return this.overrides; } public String authValue() { return this.credentials.authValue(); }
// Path: src/main/java/com/cdancy/artifactory/rest/auth/AuthenticationType.java // public enum AuthenticationType { // // Basic("Basic"), // Bearer("Bearer"), // Anonymous(""); // // private final String type; // // private AuthenticationType(final String type) { // this.type = type; // } // // @Override // public String toString() { // return type; // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryAuthenticationModule.java // public class ArtifactoryAuthenticationModule extends AbstractModule { // // private final ArtifactoryAuthentication authentication; // // public ArtifactoryAuthenticationModule(final ArtifactoryAuthentication authentication) { // this.authentication = Objects.requireNonNull(authentication); // } // // @Override // protected void configure() { // bind(ArtifactoryAuthentication.class).toProvider(new ArtifactoryAuthenticationProvider(authentication)); // } // } // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryClient.java import com.cdancy.artifactory.rest.auth.AuthenticationType; import com.cdancy.artifactory.rest.config.ArtifactoryAuthenticationModule; import com.google.common.collect.Lists; import java.util.Properties; import java.io.Closeable; import java.io.IOException; import org.jclouds.ContextBuilder; import org.jclouds.javax.annotation.Nullable; * the potentially passed in overrides with those. * * @param possibleOverrides Optional passed in overrides. * @return Properties object. */ private Properties mergeOverrides(final Properties possibleOverrides) { final Properties inferOverrides = ArtifactoryUtils.inferOverrides(); if (possibleOverrides != null) { inferOverrides.putAll(possibleOverrides); } return inferOverrides; } public String endPoint() { return this.endPoint; } @Deprecated public String credentials() { return this.authValue(); } public Properties overrides() { return this.overrides; } public String authValue() { return this.credentials.authValue(); }
public AuthenticationType authType() {
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/domain/storage/FileList.java
// Path: src/main/java/com/cdancy/artifactory/rest/domain/artifact/Artifact.java // @AutoValue // public abstract class Artifact { // // public abstract String uri(); // // @Nullable // public abstract String downloadUri(); // // @Nullable // public abstract String repo(); // // @Nullable // public abstract String path(); // // @Nullable // public abstract String remoteUrl(); // // @Nullable // public abstract String created(); // // @Nullable // public abstract String createdBy(); // // public abstract String size(); // // @Nullable // public abstract String lastModified(); // // @Nullable // public abstract String modifiedBy(); // // @Nullable // public abstract String folder(); // // @Nullable // public abstract String mimeType(); // // @Nullable // public abstract CheckSum checksums(); // // @Nullable // public abstract CheckSum originalChecksums(); // // Artifact() { // } // // @SerializedNames({ "uri", "downloadUri", "repo", "path", "remoteUrl", "created", "createdBy", // "size", "lastModified", "modifiedBy", "folder", "mimeType", "checksums", "originalChecksums" }) // public static Artifact create(String uri, String downloadUri, String repo, // String path, String remoteUrl, String created, String createdBy, // String size, String lastModified, String modifiedBy, String folder, // String mimeType, CheckSum checksums, CheckSum originalChecksums) { // return new AutoValue_Artifact(uri, downloadUri, repo, path, remoteUrl, // created, createdBy, size, lastModified, modifiedBy, // folder, mimeType, checksums, originalChecksums); // } // }
import com.cdancy.artifactory.rest.domain.artifact.Artifact; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import org.jclouds.json.SerializedNames; import java.util.List;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.domain.storage; @AutoValue public abstract class FileList { public abstract String uri(); public abstract String created();
// Path: src/main/java/com/cdancy/artifactory/rest/domain/artifact/Artifact.java // @AutoValue // public abstract class Artifact { // // public abstract String uri(); // // @Nullable // public abstract String downloadUri(); // // @Nullable // public abstract String repo(); // // @Nullable // public abstract String path(); // // @Nullable // public abstract String remoteUrl(); // // @Nullable // public abstract String created(); // // @Nullable // public abstract String createdBy(); // // public abstract String size(); // // @Nullable // public abstract String lastModified(); // // @Nullable // public abstract String modifiedBy(); // // @Nullable // public abstract String folder(); // // @Nullable // public abstract String mimeType(); // // @Nullable // public abstract CheckSum checksums(); // // @Nullable // public abstract CheckSum originalChecksums(); // // Artifact() { // } // // @SerializedNames({ "uri", "downloadUri", "repo", "path", "remoteUrl", "created", "createdBy", // "size", "lastModified", "modifiedBy", "folder", "mimeType", "checksums", "originalChecksums" }) // public static Artifact create(String uri, String downloadUri, String repo, // String path, String remoteUrl, String created, String createdBy, // String size, String lastModified, String modifiedBy, String folder, // String mimeType, CheckSum checksums, CheckSum originalChecksums) { // return new AutoValue_Artifact(uri, downloadUri, repo, path, remoteUrl, // created, createdBy, size, lastModified, modifiedBy, // folder, mimeType, checksums, originalChecksums); // } // } // Path: src/main/java/com/cdancy/artifactory/rest/domain/storage/FileList.java import com.cdancy.artifactory.rest.domain.artifact.Artifact; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import org.jclouds.json.SerializedNames; import java.util.List; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.domain.storage; @AutoValue public abstract class FileList { public abstract String uri(); public abstract String created();
public abstract List<Artifact> files();
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/SystemApiMockTest.java
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // }
import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.system.Version; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import javax.ws.rs.core.MediaType;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link com.cdancy.artifactory.rest.features.SystemApi} * class. */ @Test(groups = "unit", testName = "SystemApiMockTest") public class SystemApiMockTest extends BaseArtifactoryMockTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; public void testGetVersion() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/version.json")).setResponseCode(200));
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/SystemApiMockTest.java import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.system.Version; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import javax.ws.rs.core.MediaType; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link com.cdancy.artifactory.rest.features.SystemApi} * class. */ @Test(groups = "unit", testName = "SystemApiMockTest") public class SystemApiMockTest extends BaseArtifactoryMockTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; public void testGetVersion() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/version.json")).setResponseCode(200));
ArtifactoryApi jcloudsApi = api(server.getUrl("/"));
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/SystemApiMockTest.java
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // }
import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.system.Version; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import javax.ws.rs.core.MediaType;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link com.cdancy.artifactory.rest.features.SystemApi} * class. */ @Test(groups = "unit", testName = "SystemApiMockTest") public class SystemApiMockTest extends BaseArtifactoryMockTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; public void testGetVersion() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/version.json")).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); SystemApi api = jcloudsApi.systemApi(); try {
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/SystemApiMockTest.java import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.system.Version; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import javax.ws.rs.core.MediaType; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link com.cdancy.artifactory.rest.features.SystemApi} * class. */ @Test(groups = "unit", testName = "SystemApiMockTest") public class SystemApiMockTest extends BaseArtifactoryMockTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; public void testGetVersion() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/version.json")).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); SystemApi api = jcloudsApi.systemApi(); try {
Version version = api.version();
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/SystemApiMockTest.java
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // }
import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.system.Version; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import javax.ws.rs.core.MediaType;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link com.cdancy.artifactory.rest.features.SystemApi} * class. */ @Test(groups = "unit", testName = "SystemApiMockTest") public class SystemApiMockTest extends BaseArtifactoryMockTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; public void testGetVersion() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/version.json")).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); SystemApi api = jcloudsApi.systemApi(); try { Version version = api.version();
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/SystemApiMockTest.java import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.system.Version; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import javax.ws.rs.core.MediaType; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link com.cdancy.artifactory.rest.features.SystemApi} * class. */ @Test(groups = "unit", testName = "SystemApiMockTest") public class SystemApiMockTest extends BaseArtifactoryMockTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; public void testGetVersion() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/version.json")).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); SystemApi api = jcloudsApi.systemApi(); try { Version version = api.version();
assertNotNull(version);
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/SystemApiMockTest.java
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // }
import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.system.Version; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import javax.ws.rs.core.MediaType;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link com.cdancy.artifactory.rest.features.SystemApi} * class. */ @Test(groups = "unit", testName = "SystemApiMockTest") public class SystemApiMockTest extends BaseArtifactoryMockTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; public void testGetVersion() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/version.json")).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); SystemApi api = jcloudsApi.systemApi(); try { Version version = api.version(); assertNotNull(version);
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApi.java // public interface ArtifactoryApi extends Closeable { // // @Delegate // ArtifactApi artifactApi(); // // @Delegate // BuildApi buildApi(); // // @Delegate // DockerApi dockerApi(); // // @Delegate // RepositoryApi respositoryApi(); // // @Delegate // SearchApi searchApi(); // // @Delegate // StorageApi storageApi(); // // @Delegate // SystemApi systemApi(); // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryMockTest.java // public class BaseArtifactoryMockTest { // // protected String provider; // // public BaseArtifactoryMockTest() { // provider = "artifactory"; // } // // public ArtifactoryApi api(URL url) { // final ArtifactoryAuthentication creds = ArtifactoryAuthentication // .builder() // .credentials("hello:world") // .build(); // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(creds); // return ContextBuilder.newBuilder(provider) // .endpoint(url.toString()) // .overrides(setupProperties()) // .modules(Lists.newArrayList(credsModule)) // .buildApi(ArtifactoryApi.class); // } // // protected Properties setupProperties() { // Properties properties = new Properties(); // properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return properties; // } // // public static MockWebServer mockArtifactoryJavaWebServer() throws IOException { // MockWebServer server = new MockWebServer(); // server.start(); // return server; // } // // public String randomString() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String payloadFromResource(String resource) { // try { // return new String(toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8)); // } catch (IOException e) { // throw Throwables.propagate(e); // } // } // // protected RecordedRequest assertSent(MockWebServer server, String method, String path, String mediaType) throws InterruptedException { // RecordedRequest request = server.takeRequest(); // assertThat(request.getMethod()).isEqualTo(method); // assertThat(request.getPath()).isEqualTo(path); // assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(mediaType); // return request; // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/SystemApiMockTest.java import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.ArtifactoryApi; import com.cdancy.artifactory.rest.domain.system.Version; import com.cdancy.artifactory.rest.BaseArtifactoryMockTest; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; import javax.ws.rs.core.MediaType; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; /** * Mock tests for the {@link com.cdancy.artifactory.rest.features.SystemApi} * class. */ @Test(groups = "unit", testName = "SystemApiMockTest") public class SystemApiMockTest extends BaseArtifactoryMockTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; public void testGetVersion() throws Exception { MockWebServer server = mockArtifactoryJavaWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/version.json")).setResponseCode(200)); ArtifactoryApi jcloudsApi = api(server.getUrl("/")); SystemApi api = jcloudsApi.systemApi(); try { Version version = api.version(); assertNotNull(version);
assertTrue(version.version().matches(versionRegex));
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/SystemApiLiveTest.java
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryApiLiveTest.java // @Test(groups = "live") // public class BaseArtifactoryApiLiveTest extends BaseApiLiveTest<ArtifactoryApi> { // protected final ArtifactoryAuthentication artifactoryAuthentication; // // public BaseArtifactoryApiLiveTest() { // provider = "artifactory"; // this.artifactoryAuthentication = TestUtilities.inferTestAuthentication(); // } // // @Override // protected Iterable<Module> setupModules() { // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(this.artifactoryAuthentication); // return ImmutableSet.<Module> of(getLoggingModule(), credsModule); // } // // @Override // protected Properties setupProperties() { // Properties overrides = super.setupProperties(); // overrides.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return overrides; // } // // public String randomUUID() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String randomPath() { // return UUID.randomUUID().toString().replaceAll("-", "/"); // } // // public String randomString() { // char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray(); // StringBuilder sb = new StringBuilder(); // Random random = new Random(); // for (int i = 0; i < 10; i++) { // char c = chars[random.nextInt(chars.length)]; // sb.append(c); // } // return sb.toString(); // } // // public File randomFile() { // File randomFile = null; // PrintWriter writer = null; // try { // randomFile = new File(System.getProperty("java.io.tmpdir"), randomUUID() + ".txt"); // if (!randomFile.createNewFile()) { // throw new RuntimeException("Could not create temporary file at " + randomFile.getAbsolutePath()); // } // // writer = new PrintWriter(randomFile, "UTF-8"); // writer.println("Hello, World!"); // writer.close(); // } catch (IOException e) { // if (randomFile != null) { // randomFile.delete(); // } // throw Throwables.propagate(e); // } finally { // if (writer != null) // writer.close(); // } // return randomFile; // } // // public static String getFileChecksum(MessageDigest digest, File file) throws IOException { // //Get file input stream for reading the file content // FileInputStream fis = new FileInputStream(file); // // //Create byte array to read data in chunks // byte[] byteArray = new byte[1024]; // int bytesCount = 0; // // //Read file data and update in message digest // while ((bytesCount = fis.read(byteArray)) != -1) { // digest.update(byteArray, 0, bytesCount); // }; // // //close the stream; We don't need it now. // fis.close(); // // //Get the hash's bytes // byte[] bytes = digest.digest(); // // //This bytes[] has bytes in decimal format; // //Convert it to hexadecimal format // StringBuilder sb = new StringBuilder(); // for(int i=0; i< bytes.length ;i++) { // sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); // } // // //return complete hash // return sb.toString(); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // }
import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.BaseArtifactoryApiLiveTest; import com.cdancy.artifactory.rest.domain.system.Version;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Test(groups = "live", testName = "SystemApiLiveTest") public class SystemApiLiveTest extends BaseArtifactoryApiLiveTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; @Test public void testGetVersion() {
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryApiLiveTest.java // @Test(groups = "live") // public class BaseArtifactoryApiLiveTest extends BaseApiLiveTest<ArtifactoryApi> { // protected final ArtifactoryAuthentication artifactoryAuthentication; // // public BaseArtifactoryApiLiveTest() { // provider = "artifactory"; // this.artifactoryAuthentication = TestUtilities.inferTestAuthentication(); // } // // @Override // protected Iterable<Module> setupModules() { // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(this.artifactoryAuthentication); // return ImmutableSet.<Module> of(getLoggingModule(), credsModule); // } // // @Override // protected Properties setupProperties() { // Properties overrides = super.setupProperties(); // overrides.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return overrides; // } // // public String randomUUID() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String randomPath() { // return UUID.randomUUID().toString().replaceAll("-", "/"); // } // // public String randomString() { // char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray(); // StringBuilder sb = new StringBuilder(); // Random random = new Random(); // for (int i = 0; i < 10; i++) { // char c = chars[random.nextInt(chars.length)]; // sb.append(c); // } // return sb.toString(); // } // // public File randomFile() { // File randomFile = null; // PrintWriter writer = null; // try { // randomFile = new File(System.getProperty("java.io.tmpdir"), randomUUID() + ".txt"); // if (!randomFile.createNewFile()) { // throw new RuntimeException("Could not create temporary file at " + randomFile.getAbsolutePath()); // } // // writer = new PrintWriter(randomFile, "UTF-8"); // writer.println("Hello, World!"); // writer.close(); // } catch (IOException e) { // if (randomFile != null) { // randomFile.delete(); // } // throw Throwables.propagate(e); // } finally { // if (writer != null) // writer.close(); // } // return randomFile; // } // // public static String getFileChecksum(MessageDigest digest, File file) throws IOException { // //Get file input stream for reading the file content // FileInputStream fis = new FileInputStream(file); // // //Create byte array to read data in chunks // byte[] byteArray = new byte[1024]; // int bytesCount = 0; // // //Read file data and update in message digest // while ((bytesCount = fis.read(byteArray)) != -1) { // digest.update(byteArray, 0, bytesCount); // }; // // //close the stream; We don't need it now. // fis.close(); // // //Get the hash's bytes // byte[] bytes = digest.digest(); // // //This bytes[] has bytes in decimal format; // //Convert it to hexadecimal format // StringBuilder sb = new StringBuilder(); // for(int i=0; i< bytes.length ;i++) { // sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); // } // // //return complete hash // return sb.toString(); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/SystemApiLiveTest.java import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.BaseArtifactoryApiLiveTest; import com.cdancy.artifactory.rest.domain.system.Version; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Test(groups = "live", testName = "SystemApiLiveTest") public class SystemApiLiveTest extends BaseArtifactoryApiLiveTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; @Test public void testGetVersion() {
Version version = api().version();
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/SystemApiLiveTest.java
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryApiLiveTest.java // @Test(groups = "live") // public class BaseArtifactoryApiLiveTest extends BaseApiLiveTest<ArtifactoryApi> { // protected final ArtifactoryAuthentication artifactoryAuthentication; // // public BaseArtifactoryApiLiveTest() { // provider = "artifactory"; // this.artifactoryAuthentication = TestUtilities.inferTestAuthentication(); // } // // @Override // protected Iterable<Module> setupModules() { // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(this.artifactoryAuthentication); // return ImmutableSet.<Module> of(getLoggingModule(), credsModule); // } // // @Override // protected Properties setupProperties() { // Properties overrides = super.setupProperties(); // overrides.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return overrides; // } // // public String randomUUID() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String randomPath() { // return UUID.randomUUID().toString().replaceAll("-", "/"); // } // // public String randomString() { // char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray(); // StringBuilder sb = new StringBuilder(); // Random random = new Random(); // for (int i = 0; i < 10; i++) { // char c = chars[random.nextInt(chars.length)]; // sb.append(c); // } // return sb.toString(); // } // // public File randomFile() { // File randomFile = null; // PrintWriter writer = null; // try { // randomFile = new File(System.getProperty("java.io.tmpdir"), randomUUID() + ".txt"); // if (!randomFile.createNewFile()) { // throw new RuntimeException("Could not create temporary file at " + randomFile.getAbsolutePath()); // } // // writer = new PrintWriter(randomFile, "UTF-8"); // writer.println("Hello, World!"); // writer.close(); // } catch (IOException e) { // if (randomFile != null) { // randomFile.delete(); // } // throw Throwables.propagate(e); // } finally { // if (writer != null) // writer.close(); // } // return randomFile; // } // // public static String getFileChecksum(MessageDigest digest, File file) throws IOException { // //Get file input stream for reading the file content // FileInputStream fis = new FileInputStream(file); // // //Create byte array to read data in chunks // byte[] byteArray = new byte[1024]; // int bytesCount = 0; // // //Read file data and update in message digest // while ((bytesCount = fis.read(byteArray)) != -1) { // digest.update(byteArray, 0, bytesCount); // }; // // //close the stream; We don't need it now. // fis.close(); // // //Get the hash's bytes // byte[] bytes = digest.digest(); // // //This bytes[] has bytes in decimal format; // //Convert it to hexadecimal format // StringBuilder sb = new StringBuilder(); // for(int i=0; i< bytes.length ;i++) { // sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); // } // // //return complete hash // return sb.toString(); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // }
import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.BaseArtifactoryApiLiveTest; import com.cdancy.artifactory.rest.domain.system.Version;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Test(groups = "live", testName = "SystemApiLiveTest") public class SystemApiLiveTest extends BaseArtifactoryApiLiveTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; @Test public void testGetVersion() { Version version = api().version();
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryApiLiveTest.java // @Test(groups = "live") // public class BaseArtifactoryApiLiveTest extends BaseApiLiveTest<ArtifactoryApi> { // protected final ArtifactoryAuthentication artifactoryAuthentication; // // public BaseArtifactoryApiLiveTest() { // provider = "artifactory"; // this.artifactoryAuthentication = TestUtilities.inferTestAuthentication(); // } // // @Override // protected Iterable<Module> setupModules() { // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(this.artifactoryAuthentication); // return ImmutableSet.<Module> of(getLoggingModule(), credsModule); // } // // @Override // protected Properties setupProperties() { // Properties overrides = super.setupProperties(); // overrides.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return overrides; // } // // public String randomUUID() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String randomPath() { // return UUID.randomUUID().toString().replaceAll("-", "/"); // } // // public String randomString() { // char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray(); // StringBuilder sb = new StringBuilder(); // Random random = new Random(); // for (int i = 0; i < 10; i++) { // char c = chars[random.nextInt(chars.length)]; // sb.append(c); // } // return sb.toString(); // } // // public File randomFile() { // File randomFile = null; // PrintWriter writer = null; // try { // randomFile = new File(System.getProperty("java.io.tmpdir"), randomUUID() + ".txt"); // if (!randomFile.createNewFile()) { // throw new RuntimeException("Could not create temporary file at " + randomFile.getAbsolutePath()); // } // // writer = new PrintWriter(randomFile, "UTF-8"); // writer.println("Hello, World!"); // writer.close(); // } catch (IOException e) { // if (randomFile != null) { // randomFile.delete(); // } // throw Throwables.propagate(e); // } finally { // if (writer != null) // writer.close(); // } // return randomFile; // } // // public static String getFileChecksum(MessageDigest digest, File file) throws IOException { // //Get file input stream for reading the file content // FileInputStream fis = new FileInputStream(file); // // //Create byte array to read data in chunks // byte[] byteArray = new byte[1024]; // int bytesCount = 0; // // //Read file data and update in message digest // while ((bytesCount = fis.read(byteArray)) != -1) { // digest.update(byteArray, 0, bytesCount); // }; // // //close the stream; We don't need it now. // fis.close(); // // //Get the hash's bytes // byte[] bytes = digest.digest(); // // //This bytes[] has bytes in decimal format; // //Convert it to hexadecimal format // StringBuilder sb = new StringBuilder(); // for(int i=0; i< bytes.length ;i++) { // sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); // } // // //return complete hash // return sb.toString(); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/SystemApiLiveTest.java import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.BaseArtifactoryApiLiveTest; import com.cdancy.artifactory.rest.domain.system.Version; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Test(groups = "live", testName = "SystemApiLiveTest") public class SystemApiLiveTest extends BaseArtifactoryApiLiveTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; @Test public void testGetVersion() { Version version = api().version();
assertNotNull(version);
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/features/SystemApiLiveTest.java
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryApiLiveTest.java // @Test(groups = "live") // public class BaseArtifactoryApiLiveTest extends BaseApiLiveTest<ArtifactoryApi> { // protected final ArtifactoryAuthentication artifactoryAuthentication; // // public BaseArtifactoryApiLiveTest() { // provider = "artifactory"; // this.artifactoryAuthentication = TestUtilities.inferTestAuthentication(); // } // // @Override // protected Iterable<Module> setupModules() { // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(this.artifactoryAuthentication); // return ImmutableSet.<Module> of(getLoggingModule(), credsModule); // } // // @Override // protected Properties setupProperties() { // Properties overrides = super.setupProperties(); // overrides.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return overrides; // } // // public String randomUUID() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String randomPath() { // return UUID.randomUUID().toString().replaceAll("-", "/"); // } // // public String randomString() { // char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray(); // StringBuilder sb = new StringBuilder(); // Random random = new Random(); // for (int i = 0; i < 10; i++) { // char c = chars[random.nextInt(chars.length)]; // sb.append(c); // } // return sb.toString(); // } // // public File randomFile() { // File randomFile = null; // PrintWriter writer = null; // try { // randomFile = new File(System.getProperty("java.io.tmpdir"), randomUUID() + ".txt"); // if (!randomFile.createNewFile()) { // throw new RuntimeException("Could not create temporary file at " + randomFile.getAbsolutePath()); // } // // writer = new PrintWriter(randomFile, "UTF-8"); // writer.println("Hello, World!"); // writer.close(); // } catch (IOException e) { // if (randomFile != null) { // randomFile.delete(); // } // throw Throwables.propagate(e); // } finally { // if (writer != null) // writer.close(); // } // return randomFile; // } // // public static String getFileChecksum(MessageDigest digest, File file) throws IOException { // //Get file input stream for reading the file content // FileInputStream fis = new FileInputStream(file); // // //Create byte array to read data in chunks // byte[] byteArray = new byte[1024]; // int bytesCount = 0; // // //Read file data and update in message digest // while ((bytesCount = fis.read(byteArray)) != -1) { // digest.update(byteArray, 0, bytesCount); // }; // // //close the stream; We don't need it now. // fis.close(); // // //Get the hash's bytes // byte[] bytes = digest.digest(); // // //This bytes[] has bytes in decimal format; // //Convert it to hexadecimal format // StringBuilder sb = new StringBuilder(); // for(int i=0; i< bytes.length ;i++) { // sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); // } // // //return complete hash // return sb.toString(); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // }
import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.BaseArtifactoryApiLiveTest; import com.cdancy.artifactory.rest.domain.system.Version;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Test(groups = "live", testName = "SystemApiLiveTest") public class SystemApiLiveTest extends BaseArtifactoryApiLiveTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; @Test public void testGetVersion() { Version version = api().version(); assertNotNull(version);
// Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertNotNull(Object value) { // assertThat(value).isNotNull(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/TestUtilities.java // public static void assertTrue(boolean value) { // assertThat(value).isTrue(); // } // // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryApiLiveTest.java // @Test(groups = "live") // public class BaseArtifactoryApiLiveTest extends BaseApiLiveTest<ArtifactoryApi> { // protected final ArtifactoryAuthentication artifactoryAuthentication; // // public BaseArtifactoryApiLiveTest() { // provider = "artifactory"; // this.artifactoryAuthentication = TestUtilities.inferTestAuthentication(); // } // // @Override // protected Iterable<Module> setupModules() { // final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(this.artifactoryAuthentication); // return ImmutableSet.<Module> of(getLoggingModule(), credsModule); // } // // @Override // protected Properties setupProperties() { // Properties overrides = super.setupProperties(); // overrides.setProperty(Constants.PROPERTY_MAX_RETRIES, "0"); // return overrides; // } // // public String randomUUID() { // return UUID.randomUUID().toString().replaceAll("-", ""); // } // // public String randomPath() { // return UUID.randomUUID().toString().replaceAll("-", "/"); // } // // public String randomString() { // char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray(); // StringBuilder sb = new StringBuilder(); // Random random = new Random(); // for (int i = 0; i < 10; i++) { // char c = chars[random.nextInt(chars.length)]; // sb.append(c); // } // return sb.toString(); // } // // public File randomFile() { // File randomFile = null; // PrintWriter writer = null; // try { // randomFile = new File(System.getProperty("java.io.tmpdir"), randomUUID() + ".txt"); // if (!randomFile.createNewFile()) { // throw new RuntimeException("Could not create temporary file at " + randomFile.getAbsolutePath()); // } // // writer = new PrintWriter(randomFile, "UTF-8"); // writer.println("Hello, World!"); // writer.close(); // } catch (IOException e) { // if (randomFile != null) { // randomFile.delete(); // } // throw Throwables.propagate(e); // } finally { // if (writer != null) // writer.close(); // } // return randomFile; // } // // public static String getFileChecksum(MessageDigest digest, File file) throws IOException { // //Get file input stream for reading the file content // FileInputStream fis = new FileInputStream(file); // // //Create byte array to read data in chunks // byte[] byteArray = new byte[1024]; // int bytesCount = 0; // // //Read file data and update in message digest // while ((bytesCount = fis.read(byteArray)) != -1) { // digest.update(byteArray, 0, bytesCount); // }; // // //close the stream; We don't need it now. // fis.close(); // // //Get the hash's bytes // byte[] bytes = digest.digest(); // // //This bytes[] has bytes in decimal format; // //Convert it to hexadecimal format // StringBuilder sb = new StringBuilder(); // for(int i=0; i< bytes.length ;i++) { // sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); // } // // //return complete hash // return sb.toString(); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/system/Version.java // @AutoValue // public abstract class Version { // // public abstract String version(); // // public abstract String revision(); // // public abstract List<String> addons(); // // public abstract String license(); // // Version() { // } // // @SerializedNames({ "version", "revision", "addons", "license" }) // public static Version create(String version, String revision, List<String> addons, String license) { // return new AutoValue_Version(version, revision, // addons != null ? ImmutableList.copyOf(addons) : ImmutableList.<String> of(), license); // } // } // Path: src/test/java/com/cdancy/artifactory/rest/features/SystemApiLiveTest.java import static com.cdancy.artifactory.rest.TestUtilities.assertNotNull; import static com.cdancy.artifactory.rest.TestUtilities.assertTrue; import org.testng.annotations.Test; import com.cdancy.artifactory.rest.BaseArtifactoryApiLiveTest; import com.cdancy.artifactory.rest.domain.system.Version; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Test(groups = "live", testName = "SystemApiLiveTest") public class SystemApiLiveTest extends BaseArtifactoryApiLiveTest { private final String versionRegex = "^\\d+\\.\\d+\\.\\d+$"; @Test public void testGetVersion() { Version version = api().version(); assertNotNull(version);
assertTrue(version.version().matches(versionRegex));
cdancy/artifactory-rest
src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryApiLiveTest.java
// Path: src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryAuthenticationModule.java // public class ArtifactoryAuthenticationModule extends AbstractModule { // // private final ArtifactoryAuthentication authentication; // // public ArtifactoryAuthenticationModule(final ArtifactoryAuthentication authentication) { // this.authentication = Objects.requireNonNull(authentication); // } // // @Override // protected void configure() { // bind(ArtifactoryAuthentication.class).toProvider(new ArtifactoryAuthenticationProvider(authentication)); // } // }
import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; import com.cdancy.artifactory.rest.config.ArtifactoryAuthenticationModule; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.PrintWriter; import java.security.MessageDigest; import java.util.Properties; import java.util.Random; import java.util.UUID; import org.jclouds.Constants; import org.jclouds.apis.BaseApiLiveTest; import org.testng.annotations.Test;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest; @Test(groups = "live") public class BaseArtifactoryApiLiveTest extends BaseApiLiveTest<ArtifactoryApi> { protected final ArtifactoryAuthentication artifactoryAuthentication; public BaseArtifactoryApiLiveTest() { provider = "artifactory"; this.artifactoryAuthentication = TestUtilities.inferTestAuthentication(); } @Override protected Iterable<Module> setupModules() {
// Path: src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryAuthenticationModule.java // public class ArtifactoryAuthenticationModule extends AbstractModule { // // private final ArtifactoryAuthentication authentication; // // public ArtifactoryAuthenticationModule(final ArtifactoryAuthentication authentication) { // this.authentication = Objects.requireNonNull(authentication); // } // // @Override // protected void configure() { // bind(ArtifactoryAuthentication.class).toProvider(new ArtifactoryAuthenticationProvider(authentication)); // } // } // Path: src/test/java/com/cdancy/artifactory/rest/BaseArtifactoryApiLiveTest.java import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; import com.cdancy.artifactory.rest.config.ArtifactoryAuthenticationModule; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.PrintWriter; import java.security.MessageDigest; import java.util.Properties; import java.util.Random; import java.util.UUID; import org.jclouds.Constants; import org.jclouds.apis.BaseApiLiveTest; import org.testng.annotations.Test; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest; @Test(groups = "live") public class BaseArtifactoryApiLiveTest extends BaseApiLiveTest<ArtifactoryApi> { protected final ArtifactoryAuthentication artifactoryAuthentication; public BaseArtifactoryApiLiveTest() { provider = "artifactory"; this.artifactoryAuthentication = TestUtilities.inferTestAuthentication(); } @Override protected Iterable<Module> setupModules() {
final ArtifactoryAuthenticationModule credsModule = new ArtifactoryAuthenticationModule(this.artifactoryAuthentication);
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Error.java // @AutoValue // public abstract class Error { // // public abstract int status(); // // public abstract String message(); // // Error() { // } // // @SerializedNames({ "status", "message" }) // public static Error create(int level, String message) { // return new AutoValue_Error(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Message.java // @AutoValue // public abstract class Message { // // public abstract String level(); // // public abstract String message(); // // Message() { // } // // @SerializedNames({ "level", "message" }) // public static Message create(String level, String message) { // return new AutoValue_Message(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // }
import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.propagate; import java.io.StringReader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import com.cdancy.artifactory.rest.domain.error.Error; import com.cdancy.artifactory.rest.domain.error.Message; import com.cdancy.artifactory.rest.domain.error.RequestStatus; import com.google.gson.JsonArray; import com.google.gson.stream.JsonReader; import org.jclouds.Fallback;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.fallbacks; public final class ArtifactoryFallbacks { private static final JsonParser PARSER = new JsonParser(); public static final class RequestStatusFromError implements Fallback<Object> { public Object createOrPropagate(Throwable t) throws Exception { if (checkNotNull(t, "throwable") != null) {
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Error.java // @AutoValue // public abstract class Error { // // public abstract int status(); // // public abstract String message(); // // Error() { // } // // @SerializedNames({ "status", "message" }) // public static Error create(int level, String message) { // return new AutoValue_Error(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Message.java // @AutoValue // public abstract class Message { // // public abstract String level(); // // public abstract String message(); // // Message() { // } // // @SerializedNames({ "level", "message" }) // public static Message create(String level, String message) { // return new AutoValue_Message(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // } // Path: src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.propagate; import java.io.StringReader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import com.cdancy.artifactory.rest.domain.error.Error; import com.cdancy.artifactory.rest.domain.error.Message; import com.cdancy.artifactory.rest.domain.error.RequestStatus; import com.google.gson.JsonArray; import com.google.gson.stream.JsonReader; import org.jclouds.Fallback; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.fallbacks; public final class ArtifactoryFallbacks { private static final JsonParser PARSER = new JsonParser(); public static final class RequestStatusFromError implements Fallback<Object> { public Object createOrPropagate(Throwable t) throws Exception { if (checkNotNull(t, "throwable") != null) {
RequestStatus status = createPromoteBuildFromError(t.getMessage());
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Error.java // @AutoValue // public abstract class Error { // // public abstract int status(); // // public abstract String message(); // // Error() { // } // // @SerializedNames({ "status", "message" }) // public static Error create(int level, String message) { // return new AutoValue_Error(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Message.java // @AutoValue // public abstract class Message { // // public abstract String level(); // // public abstract String message(); // // Message() { // } // // @SerializedNames({ "level", "message" }) // public static Message create(String level, String message) { // return new AutoValue_Message(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // }
import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.propagate; import java.io.StringReader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import com.cdancy.artifactory.rest.domain.error.Error; import com.cdancy.artifactory.rest.domain.error.Message; import com.cdancy.artifactory.rest.domain.error.RequestStatus; import com.google.gson.JsonArray; import com.google.gson.stream.JsonReader; import org.jclouds.Fallback;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.fallbacks; public final class ArtifactoryFallbacks { private static final JsonParser PARSER = new JsonParser(); public static final class RequestStatusFromError implements Fallback<Object> { public Object createOrPropagate(Throwable t) throws Exception { if (checkNotNull(t, "throwable") != null) { RequestStatus status = createPromoteBuildFromError(t.getMessage()); if (status != null) { return status; } } throw propagate(t); } } public static RequestStatus createPromoteBuildFromError(String message) {
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Error.java // @AutoValue // public abstract class Error { // // public abstract int status(); // // public abstract String message(); // // Error() { // } // // @SerializedNames({ "status", "message" }) // public static Error create(int level, String message) { // return new AutoValue_Error(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Message.java // @AutoValue // public abstract class Message { // // public abstract String level(); // // public abstract String message(); // // Message() { // } // // @SerializedNames({ "level", "message" }) // public static Message create(String level, String message) { // return new AutoValue_Message(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // } // Path: src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.propagate; import java.io.StringReader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import com.cdancy.artifactory.rest.domain.error.Error; import com.cdancy.artifactory.rest.domain.error.Message; import com.cdancy.artifactory.rest.domain.error.RequestStatus; import com.google.gson.JsonArray; import com.google.gson.stream.JsonReader; import org.jclouds.Fallback; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.fallbacks; public final class ArtifactoryFallbacks { private static final JsonParser PARSER = new JsonParser(); public static final class RequestStatusFromError implements Fallback<Object> { public Object createOrPropagate(Throwable t) throws Exception { if (checkNotNull(t, "throwable") != null) { RequestStatus status = createPromoteBuildFromError(t.getMessage()); if (status != null) { return status; } } throw propagate(t); } } public static RequestStatus createPromoteBuildFromError(String message) {
List<Message> messages = new ArrayList<>();
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Error.java // @AutoValue // public abstract class Error { // // public abstract int status(); // // public abstract String message(); // // Error() { // } // // @SerializedNames({ "status", "message" }) // public static Error create(int level, String message) { // return new AutoValue_Error(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Message.java // @AutoValue // public abstract class Message { // // public abstract String level(); // // public abstract String message(); // // Message() { // } // // @SerializedNames({ "level", "message" }) // public static Message create(String level, String message) { // return new AutoValue_Message(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // }
import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.propagate; import java.io.StringReader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import com.cdancy.artifactory.rest.domain.error.Error; import com.cdancy.artifactory.rest.domain.error.Message; import com.cdancy.artifactory.rest.domain.error.RequestStatus; import com.google.gson.JsonArray; import com.google.gson.stream.JsonReader; import org.jclouds.Fallback;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.fallbacks; public final class ArtifactoryFallbacks { private static final JsonParser PARSER = new JsonParser(); public static final class RequestStatusFromError implements Fallback<Object> { public Object createOrPropagate(Throwable t) throws Exception { if (checkNotNull(t, "throwable") != null) { RequestStatus status = createPromoteBuildFromError(t.getMessage()); if (status != null) { return status; } } throw propagate(t); } } public static RequestStatus createPromoteBuildFromError(String message) { List<Message> messages = new ArrayList<>();
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Error.java // @AutoValue // public abstract class Error { // // public abstract int status(); // // public abstract String message(); // // Error() { // } // // @SerializedNames({ "status", "message" }) // public static Error create(int level, String message) { // return new AutoValue_Error(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/Message.java // @AutoValue // public abstract class Message { // // public abstract String level(); // // public abstract String message(); // // Message() { // } // // @SerializedNames({ "level", "message" }) // public static Message create(String level, String message) { // return new AutoValue_Message(level, message); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // } // Path: src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.propagate; import java.io.StringReader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import com.cdancy.artifactory.rest.domain.error.Error; import com.cdancy.artifactory.rest.domain.error.Message; import com.cdancy.artifactory.rest.domain.error.RequestStatus; import com.google.gson.JsonArray; import com.google.gson.stream.JsonReader; import org.jclouds.Fallback; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.fallbacks; public final class ArtifactoryFallbacks { private static final JsonParser PARSER = new JsonParser(); public static final class RequestStatusFromError implements Fallback<Object> { public Object createOrPropagate(Throwable t) throws Exception { if (checkNotNull(t, "throwable") != null) { RequestStatus status = createPromoteBuildFromError(t.getMessage()); if (status != null) { return status; } } throw propagate(t); } } public static RequestStatus createPromoteBuildFromError(String message) { List<Message> messages = new ArrayList<>();
List<Error> errors = new ArrayList<>();
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/ArtifactoryApiMetadata.java
// Path: src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryHttpApiModule.java // @ConfiguresHttpApi // public class ArtifactoryHttpApiModule extends HttpApiModule<ArtifactoryApi> { // // @Override // protected void bindErrorHandlers() { // bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ArtifactoryErrorHandler.class); // bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ArtifactoryErrorHandler.class); // bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ArtifactoryErrorHandler.class); // } // }
import java.net.URI; import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.rest.internal.BaseHttpApiMetadata; import com.cdancy.artifactory.rest.config.ArtifactoryHttpApiModule; import com.google.auto.service.AutoService; import com.google.common.collect.ImmutableSet; import com.google.inject.Module;
return new Builder().fromApiMetadata(this); } public ArtifactoryApiMetadata() { this(new Builder()); } protected ArtifactoryApiMetadata(Builder builder) { super(builder); } public static Properties defaultProperties() { final Properties properties = BaseHttpApiMetadata.defaultProperties(); return properties; } public static class Builder extends BaseHttpApiMetadata.Builder<ArtifactoryApi, Builder> { protected Builder() { super(ArtifactoryApi.class); id("artifactory").name("Artifactory REST API") .identityName("Optional Username") .credentialName("Optional Password") .defaultIdentity("") .defaultCredential("") .documentation(URI.create("https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API")) .version(API_VERSION) .buildVersion(BUILD_VERSION) .defaultEndpoint("http://127.0.0.1:8081/artifactory") .defaultProperties(ArtifactoryApiMetadata.defaultProperties())
// Path: src/main/java/com/cdancy/artifactory/rest/config/ArtifactoryHttpApiModule.java // @ConfiguresHttpApi // public class ArtifactoryHttpApiModule extends HttpApiModule<ArtifactoryApi> { // // @Override // protected void bindErrorHandlers() { // bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ArtifactoryErrorHandler.class); // bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ArtifactoryErrorHandler.class); // bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ArtifactoryErrorHandler.class); // } // } // Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryApiMetadata.java import java.net.URI; import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.rest.internal.BaseHttpApiMetadata; import com.cdancy.artifactory.rest.config.ArtifactoryHttpApiModule; import com.google.auto.service.AutoService; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; return new Builder().fromApiMetadata(this); } public ArtifactoryApiMetadata() { this(new Builder()); } protected ArtifactoryApiMetadata(Builder builder) { super(builder); } public static Properties defaultProperties() { final Properties properties = BaseHttpApiMetadata.defaultProperties(); return properties; } public static class Builder extends BaseHttpApiMetadata.Builder<ArtifactoryApi, Builder> { protected Builder() { super(ArtifactoryApi.class); id("artifactory").name("Artifactory REST API") .identityName("Optional Username") .credentialName("Optional Password") .defaultIdentity("") .defaultCredential("") .documentation(URI.create("https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API")) .version(API_VERSION) .buildVersion(BUILD_VERSION) .defaultEndpoint("http://127.0.0.1:8081/artifactory") .defaultProperties(ArtifactoryApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>> of(ArtifactoryHttpApiModule.class));
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/features/RepositoryApi.java
// Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // }
import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api/repositories") @Consumes(MediaType.APPLICATION_JSON)
// Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // } // Path: src/main/java/com/cdancy/artifactory/rest/features/RepositoryApi.java import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api/repositories") @Consumes(MediaType.APPLICATION_JSON)
@RequestFilters(ArtifactoryAuthenticationFilter.class)
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/features/BuildApi.java
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java // public static final class RequestStatusFromError implements Fallback<Object> { // public Object createOrPropagate(Throwable t) throws Exception { // if (checkNotNull(t, "throwable") != null) { // RequestStatus status = createPromoteBuildFromError(t.getMessage()); // if (status != null) { // return status; // } // } // throw propagate(t); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/options/PromoteBuildOptions.java // @AutoValue // public abstract class PromoteBuildOptions { // // public abstract String status(); // defaults to 'promoted' // // public abstract String comment(); // default to 'error promoted' // // @Nullable // public abstract String ciUser(); // // @Nullable // public abstract String timestamp(); // must be in format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ' // // public abstract boolean dryRun(); // // public abstract String sourceRepo(); // // public abstract String targetRepo(); // // public abstract boolean copy(); // // public abstract boolean artifacts(); // // public abstract boolean dependencies(); // // @Nullable // public abstract List<String> scopes(); // // @Nullable // public abstract Map<String, List<String>> properties(); // // public abstract boolean failFast(); // // PromoteBuildOptions() { // } // // @SerializedNames({ "status", "comment", "ciUser", "timestamp", "dryRun", "sourceRepo", "targetRepo", // "copy", "artifacts", "dependencies", "scopes", "properties", "failFast" }) // public static PromoteBuildOptions create(String status, String comment, String ciUser, String timestamp, // boolean dryRun, String sourceRepo, String targetRepo, boolean copy, // boolean artifacts, boolean dependencies, List<String> scopes, // Map<String, List<String>> properties, boolean failFast) { // return new AutoValue_PromoteBuildOptions(status != null ? status : "promoted", comment != null ? comment : "error promoted", ciUser, timestamp, // dryRun, sourceRepo, targetRepo, copy, // artifacts, dependencies, scopes, properties, failFast); // } // }
import com.cdancy.artifactory.rest.domain.error.RequestStatus; import static com.cdancy.artifactory.rest.fallbacks.ArtifactoryFallbacks.RequestStatusFromError; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import com.cdancy.artifactory.rest.options.PromoteBuildOptions; import org.jclouds.rest.annotations.*; import org.jclouds.rest.binders.BindToJsonPayload; import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api") @Consumes(MediaType.APPLICATION_JSON)
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java // public static final class RequestStatusFromError implements Fallback<Object> { // public Object createOrPropagate(Throwable t) throws Exception { // if (checkNotNull(t, "throwable") != null) { // RequestStatus status = createPromoteBuildFromError(t.getMessage()); // if (status != null) { // return status; // } // } // throw propagate(t); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/options/PromoteBuildOptions.java // @AutoValue // public abstract class PromoteBuildOptions { // // public abstract String status(); // defaults to 'promoted' // // public abstract String comment(); // default to 'error promoted' // // @Nullable // public abstract String ciUser(); // // @Nullable // public abstract String timestamp(); // must be in format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ' // // public abstract boolean dryRun(); // // public abstract String sourceRepo(); // // public abstract String targetRepo(); // // public abstract boolean copy(); // // public abstract boolean artifacts(); // // public abstract boolean dependencies(); // // @Nullable // public abstract List<String> scopes(); // // @Nullable // public abstract Map<String, List<String>> properties(); // // public abstract boolean failFast(); // // PromoteBuildOptions() { // } // // @SerializedNames({ "status", "comment", "ciUser", "timestamp", "dryRun", "sourceRepo", "targetRepo", // "copy", "artifacts", "dependencies", "scopes", "properties", "failFast" }) // public static PromoteBuildOptions create(String status, String comment, String ciUser, String timestamp, // boolean dryRun, String sourceRepo, String targetRepo, boolean copy, // boolean artifacts, boolean dependencies, List<String> scopes, // Map<String, List<String>> properties, boolean failFast) { // return new AutoValue_PromoteBuildOptions(status != null ? status : "promoted", comment != null ? comment : "error promoted", ciUser, timestamp, // dryRun, sourceRepo, targetRepo, copy, // artifacts, dependencies, scopes, properties, failFast); // } // } // Path: src/main/java/com/cdancy/artifactory/rest/features/BuildApi.java import com.cdancy.artifactory.rest.domain.error.RequestStatus; import static com.cdancy.artifactory.rest.fallbacks.ArtifactoryFallbacks.RequestStatusFromError; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import com.cdancy.artifactory.rest.options.PromoteBuildOptions; import org.jclouds.rest.annotations.*; import org.jclouds.rest.binders.BindToJsonPayload; import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api") @Consumes(MediaType.APPLICATION_JSON)
@RequestFilters(ArtifactoryAuthenticationFilter.class)
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/features/BuildApi.java
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java // public static final class RequestStatusFromError implements Fallback<Object> { // public Object createOrPropagate(Throwable t) throws Exception { // if (checkNotNull(t, "throwable") != null) { // RequestStatus status = createPromoteBuildFromError(t.getMessage()); // if (status != null) { // return status; // } // } // throw propagate(t); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/options/PromoteBuildOptions.java // @AutoValue // public abstract class PromoteBuildOptions { // // public abstract String status(); // defaults to 'promoted' // // public abstract String comment(); // default to 'error promoted' // // @Nullable // public abstract String ciUser(); // // @Nullable // public abstract String timestamp(); // must be in format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ' // // public abstract boolean dryRun(); // // public abstract String sourceRepo(); // // public abstract String targetRepo(); // // public abstract boolean copy(); // // public abstract boolean artifacts(); // // public abstract boolean dependencies(); // // @Nullable // public abstract List<String> scopes(); // // @Nullable // public abstract Map<String, List<String>> properties(); // // public abstract boolean failFast(); // // PromoteBuildOptions() { // } // // @SerializedNames({ "status", "comment", "ciUser", "timestamp", "dryRun", "sourceRepo", "targetRepo", // "copy", "artifacts", "dependencies", "scopes", "properties", "failFast" }) // public static PromoteBuildOptions create(String status, String comment, String ciUser, String timestamp, // boolean dryRun, String sourceRepo, String targetRepo, boolean copy, // boolean artifacts, boolean dependencies, List<String> scopes, // Map<String, List<String>> properties, boolean failFast) { // return new AutoValue_PromoteBuildOptions(status != null ? status : "promoted", comment != null ? comment : "error promoted", ciUser, timestamp, // dryRun, sourceRepo, targetRepo, copy, // artifacts, dependencies, scopes, properties, failFast); // } // }
import com.cdancy.artifactory.rest.domain.error.RequestStatus; import static com.cdancy.artifactory.rest.fallbacks.ArtifactoryFallbacks.RequestStatusFromError; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import com.cdancy.artifactory.rest.options.PromoteBuildOptions; import org.jclouds.rest.annotations.*; import org.jclouds.rest.binders.BindToJsonPayload; import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api") @Consumes(MediaType.APPLICATION_JSON) @RequestFilters(ArtifactoryAuthenticationFilter.class) public interface BuildApi { @Named("build:promote") @Path("/build/promote/{buildName}/{buildNumber}")
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java // public static final class RequestStatusFromError implements Fallback<Object> { // public Object createOrPropagate(Throwable t) throws Exception { // if (checkNotNull(t, "throwable") != null) { // RequestStatus status = createPromoteBuildFromError(t.getMessage()); // if (status != null) { // return status; // } // } // throw propagate(t); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/options/PromoteBuildOptions.java // @AutoValue // public abstract class PromoteBuildOptions { // // public abstract String status(); // defaults to 'promoted' // // public abstract String comment(); // default to 'error promoted' // // @Nullable // public abstract String ciUser(); // // @Nullable // public abstract String timestamp(); // must be in format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ' // // public abstract boolean dryRun(); // // public abstract String sourceRepo(); // // public abstract String targetRepo(); // // public abstract boolean copy(); // // public abstract boolean artifacts(); // // public abstract boolean dependencies(); // // @Nullable // public abstract List<String> scopes(); // // @Nullable // public abstract Map<String, List<String>> properties(); // // public abstract boolean failFast(); // // PromoteBuildOptions() { // } // // @SerializedNames({ "status", "comment", "ciUser", "timestamp", "dryRun", "sourceRepo", "targetRepo", // "copy", "artifacts", "dependencies", "scopes", "properties", "failFast" }) // public static PromoteBuildOptions create(String status, String comment, String ciUser, String timestamp, // boolean dryRun, String sourceRepo, String targetRepo, boolean copy, // boolean artifacts, boolean dependencies, List<String> scopes, // Map<String, List<String>> properties, boolean failFast) { // return new AutoValue_PromoteBuildOptions(status != null ? status : "promoted", comment != null ? comment : "error promoted", ciUser, timestamp, // dryRun, sourceRepo, targetRepo, copy, // artifacts, dependencies, scopes, properties, failFast); // } // } // Path: src/main/java/com/cdancy/artifactory/rest/features/BuildApi.java import com.cdancy.artifactory.rest.domain.error.RequestStatus; import static com.cdancy.artifactory.rest.fallbacks.ArtifactoryFallbacks.RequestStatusFromError; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import com.cdancy.artifactory.rest.options.PromoteBuildOptions; import org.jclouds.rest.annotations.*; import org.jclouds.rest.binders.BindToJsonPayload; import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api") @Consumes(MediaType.APPLICATION_JSON) @RequestFilters(ArtifactoryAuthenticationFilter.class) public interface BuildApi { @Named("build:promote") @Path("/build/promote/{buildName}/{buildNumber}")
@Fallback(RequestStatusFromError.class)
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/features/BuildApi.java
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java // public static final class RequestStatusFromError implements Fallback<Object> { // public Object createOrPropagate(Throwable t) throws Exception { // if (checkNotNull(t, "throwable") != null) { // RequestStatus status = createPromoteBuildFromError(t.getMessage()); // if (status != null) { // return status; // } // } // throw propagate(t); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/options/PromoteBuildOptions.java // @AutoValue // public abstract class PromoteBuildOptions { // // public abstract String status(); // defaults to 'promoted' // // public abstract String comment(); // default to 'error promoted' // // @Nullable // public abstract String ciUser(); // // @Nullable // public abstract String timestamp(); // must be in format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ' // // public abstract boolean dryRun(); // // public abstract String sourceRepo(); // // public abstract String targetRepo(); // // public abstract boolean copy(); // // public abstract boolean artifacts(); // // public abstract boolean dependencies(); // // @Nullable // public abstract List<String> scopes(); // // @Nullable // public abstract Map<String, List<String>> properties(); // // public abstract boolean failFast(); // // PromoteBuildOptions() { // } // // @SerializedNames({ "status", "comment", "ciUser", "timestamp", "dryRun", "sourceRepo", "targetRepo", // "copy", "artifacts", "dependencies", "scopes", "properties", "failFast" }) // public static PromoteBuildOptions create(String status, String comment, String ciUser, String timestamp, // boolean dryRun, String sourceRepo, String targetRepo, boolean copy, // boolean artifacts, boolean dependencies, List<String> scopes, // Map<String, List<String>> properties, boolean failFast) { // return new AutoValue_PromoteBuildOptions(status != null ? status : "promoted", comment != null ? comment : "error promoted", ciUser, timestamp, // dryRun, sourceRepo, targetRepo, copy, // artifacts, dependencies, scopes, properties, failFast); // } // }
import com.cdancy.artifactory.rest.domain.error.RequestStatus; import static com.cdancy.artifactory.rest.fallbacks.ArtifactoryFallbacks.RequestStatusFromError; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import com.cdancy.artifactory.rest.options.PromoteBuildOptions; import org.jclouds.rest.annotations.*; import org.jclouds.rest.binders.BindToJsonPayload; import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api") @Consumes(MediaType.APPLICATION_JSON) @RequestFilters(ArtifactoryAuthenticationFilter.class) public interface BuildApi { @Named("build:promote") @Path("/build/promote/{buildName}/{buildNumber}") @Fallback(RequestStatusFromError.class) @POST
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java // public static final class RequestStatusFromError implements Fallback<Object> { // public Object createOrPropagate(Throwable t) throws Exception { // if (checkNotNull(t, "throwable") != null) { // RequestStatus status = createPromoteBuildFromError(t.getMessage()); // if (status != null) { // return status; // } // } // throw propagate(t); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/options/PromoteBuildOptions.java // @AutoValue // public abstract class PromoteBuildOptions { // // public abstract String status(); // defaults to 'promoted' // // public abstract String comment(); // default to 'error promoted' // // @Nullable // public abstract String ciUser(); // // @Nullable // public abstract String timestamp(); // must be in format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ' // // public abstract boolean dryRun(); // // public abstract String sourceRepo(); // // public abstract String targetRepo(); // // public abstract boolean copy(); // // public abstract boolean artifacts(); // // public abstract boolean dependencies(); // // @Nullable // public abstract List<String> scopes(); // // @Nullable // public abstract Map<String, List<String>> properties(); // // public abstract boolean failFast(); // // PromoteBuildOptions() { // } // // @SerializedNames({ "status", "comment", "ciUser", "timestamp", "dryRun", "sourceRepo", "targetRepo", // "copy", "artifacts", "dependencies", "scopes", "properties", "failFast" }) // public static PromoteBuildOptions create(String status, String comment, String ciUser, String timestamp, // boolean dryRun, String sourceRepo, String targetRepo, boolean copy, // boolean artifacts, boolean dependencies, List<String> scopes, // Map<String, List<String>> properties, boolean failFast) { // return new AutoValue_PromoteBuildOptions(status != null ? status : "promoted", comment != null ? comment : "error promoted", ciUser, timestamp, // dryRun, sourceRepo, targetRepo, copy, // artifacts, dependencies, scopes, properties, failFast); // } // } // Path: src/main/java/com/cdancy/artifactory/rest/features/BuildApi.java import com.cdancy.artifactory.rest.domain.error.RequestStatus; import static com.cdancy.artifactory.rest.fallbacks.ArtifactoryFallbacks.RequestStatusFromError; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import com.cdancy.artifactory.rest.options.PromoteBuildOptions; import org.jclouds.rest.annotations.*; import org.jclouds.rest.binders.BindToJsonPayload; import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api") @Consumes(MediaType.APPLICATION_JSON) @RequestFilters(ArtifactoryAuthenticationFilter.class) public interface BuildApi { @Named("build:promote") @Path("/build/promote/{buildName}/{buildNumber}") @Fallback(RequestStatusFromError.class) @POST
RequestStatus promote(@PathParam("buildName") String buildName, @PathParam("buildNumber") long buildNumber,
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/features/BuildApi.java
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java // public static final class RequestStatusFromError implements Fallback<Object> { // public Object createOrPropagate(Throwable t) throws Exception { // if (checkNotNull(t, "throwable") != null) { // RequestStatus status = createPromoteBuildFromError(t.getMessage()); // if (status != null) { // return status; // } // } // throw propagate(t); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/options/PromoteBuildOptions.java // @AutoValue // public abstract class PromoteBuildOptions { // // public abstract String status(); // defaults to 'promoted' // // public abstract String comment(); // default to 'error promoted' // // @Nullable // public abstract String ciUser(); // // @Nullable // public abstract String timestamp(); // must be in format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ' // // public abstract boolean dryRun(); // // public abstract String sourceRepo(); // // public abstract String targetRepo(); // // public abstract boolean copy(); // // public abstract boolean artifacts(); // // public abstract boolean dependencies(); // // @Nullable // public abstract List<String> scopes(); // // @Nullable // public abstract Map<String, List<String>> properties(); // // public abstract boolean failFast(); // // PromoteBuildOptions() { // } // // @SerializedNames({ "status", "comment", "ciUser", "timestamp", "dryRun", "sourceRepo", "targetRepo", // "copy", "artifacts", "dependencies", "scopes", "properties", "failFast" }) // public static PromoteBuildOptions create(String status, String comment, String ciUser, String timestamp, // boolean dryRun, String sourceRepo, String targetRepo, boolean copy, // boolean artifacts, boolean dependencies, List<String> scopes, // Map<String, List<String>> properties, boolean failFast) { // return new AutoValue_PromoteBuildOptions(status != null ? status : "promoted", comment != null ? comment : "error promoted", ciUser, timestamp, // dryRun, sourceRepo, targetRepo, copy, // artifacts, dependencies, scopes, properties, failFast); // } // }
import com.cdancy.artifactory.rest.domain.error.RequestStatus; import static com.cdancy.artifactory.rest.fallbacks.ArtifactoryFallbacks.RequestStatusFromError; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import com.cdancy.artifactory.rest.options.PromoteBuildOptions; import org.jclouds.rest.annotations.*; import org.jclouds.rest.binders.BindToJsonPayload; import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api") @Consumes(MediaType.APPLICATION_JSON) @RequestFilters(ArtifactoryAuthenticationFilter.class) public interface BuildApi { @Named("build:promote") @Path("/build/promote/{buildName}/{buildNumber}") @Fallback(RequestStatusFromError.class) @POST RequestStatus promote(@PathParam("buildName") String buildName, @PathParam("buildNumber") long buildNumber,
// Path: src/main/java/com/cdancy/artifactory/rest/domain/error/RequestStatus.java // @AutoValue // public abstract class RequestStatus { // // public abstract List<Message> messages(); // // public abstract List<Error> errors(); // // RequestStatus() { // } // // @SerializedNames({ "messages", "errors" }) // public static RequestStatus create(List<Message> messages, List<Error> errors) { // return new AutoValue_RequestStatus(messages != null ? ImmutableList.copyOf(messages) : ImmutableList.<Message>of(), // errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error>of()); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/fallbacks/ArtifactoryFallbacks.java // public static final class RequestStatusFromError implements Fallback<Object> { // public Object createOrPropagate(Throwable t) throws Exception { // if (checkNotNull(t, "throwable") != null) { // RequestStatus status = createPromoteBuildFromError(t.getMessage()); // if (status != null) { // return status; // } // } // throw propagate(t); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/options/PromoteBuildOptions.java // @AutoValue // public abstract class PromoteBuildOptions { // // public abstract String status(); // defaults to 'promoted' // // public abstract String comment(); // default to 'error promoted' // // @Nullable // public abstract String ciUser(); // // @Nullable // public abstract String timestamp(); // must be in format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ' // // public abstract boolean dryRun(); // // public abstract String sourceRepo(); // // public abstract String targetRepo(); // // public abstract boolean copy(); // // public abstract boolean artifacts(); // // public abstract boolean dependencies(); // // @Nullable // public abstract List<String> scopes(); // // @Nullable // public abstract Map<String, List<String>> properties(); // // public abstract boolean failFast(); // // PromoteBuildOptions() { // } // // @SerializedNames({ "status", "comment", "ciUser", "timestamp", "dryRun", "sourceRepo", "targetRepo", // "copy", "artifacts", "dependencies", "scopes", "properties", "failFast" }) // public static PromoteBuildOptions create(String status, String comment, String ciUser, String timestamp, // boolean dryRun, String sourceRepo, String targetRepo, boolean copy, // boolean artifacts, boolean dependencies, List<String> scopes, // Map<String, List<String>> properties, boolean failFast) { // return new AutoValue_PromoteBuildOptions(status != null ? status : "promoted", comment != null ? comment : "error promoted", ciUser, timestamp, // dryRun, sourceRepo, targetRepo, copy, // artifacts, dependencies, scopes, properties, failFast); // } // } // Path: src/main/java/com/cdancy/artifactory/rest/features/BuildApi.java import com.cdancy.artifactory.rest.domain.error.RequestStatus; import static com.cdancy.artifactory.rest.fallbacks.ArtifactoryFallbacks.RequestStatusFromError; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import com.cdancy.artifactory.rest.options.PromoteBuildOptions; import org.jclouds.rest.annotations.*; import org.jclouds.rest.binders.BindToJsonPayload; import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api") @Consumes(MediaType.APPLICATION_JSON) @RequestFilters(ArtifactoryAuthenticationFilter.class) public interface BuildApi { @Named("build:promote") @Path("/build/promote/{buildName}/{buildNumber}") @Fallback(RequestStatusFromError.class) @POST RequestStatus promote(@PathParam("buildName") String buildName, @PathParam("buildNumber") long buildNumber,
@BinderParam(BindToJsonPayload.class) PromoteBuildOptions promoteBuildOptions);
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/features/DockerApi.java
// Path: src/main/java/com/cdancy/artifactory/rest/domain/docker/PromoteImage.java // @AutoValue // public abstract class PromoteImage { // // public abstract String targetRepo(); // // public abstract String dockerRepository(); // // @Nullable // public abstract String tag(); // // @Nullable // public abstract String targetTag(); // // public abstract boolean copy(); // // PromoteImage() { // } // // @SerializedNames({ "targetRepo", "dockerRepository", "tag", "targetTag", "copy" }) // public static PromoteImage create(String targetRepo, String dockerRepository, String tag, String targetTag, boolean copy) { // return new AutoValue_PromoteImage(targetRepo, dockerRepository, tag, targetTag, copy); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // }
import com.cdancy.artifactory.rest.domain.docker.PromoteImage; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import org.jclouds.Fallbacks; import org.jclouds.rest.annotations.*; import org.jclouds.rest.binders.BindToJsonPayload; import javax.inject.Named; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import java.util.List;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api/docker") @RequestFilters(ArtifactoryAuthenticationFilter.class) public interface DockerApi { @Named("docker:promote") @Consumes(MediaType.TEXT_PLAIN) @Path("/{repoKey}/v2/promote") @Fallback(Fallbacks.FalseOnNotFoundOr404.class) @POST
// Path: src/main/java/com/cdancy/artifactory/rest/domain/docker/PromoteImage.java // @AutoValue // public abstract class PromoteImage { // // public abstract String targetRepo(); // // public abstract String dockerRepository(); // // @Nullable // public abstract String tag(); // // @Nullable // public abstract String targetTag(); // // public abstract boolean copy(); // // PromoteImage() { // } // // @SerializedNames({ "targetRepo", "dockerRepository", "tag", "targetTag", "copy" }) // public static PromoteImage create(String targetRepo, String dockerRepository, String tag, String targetTag, boolean copy) { // return new AutoValue_PromoteImage(targetRepo, dockerRepository, tag, targetTag, copy); // } // } // // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java // @Singleton // public class ArtifactoryAuthenticationFilter implements HttpRequestFilter { // private final ArtifactoryAuthentication authentication; // // @Inject // ArtifactoryAuthenticationFilter(final ArtifactoryAuthentication authentication) { // this.authentication = authentication; // } // // @Override // public HttpRequest filter(HttpRequest request) throws HttpException { // switch(authentication.authType()) { // case Basic: // final String basicValue = authentication.authType() + " " + authentication.authValue(); // return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, basicValue).build(); // case Bearer: // return request.toBuilder().addHeader("X-JFrog-Art-Api", authentication.authValue()).build(); // case Anonymous: // default: // return request.toBuilder().build(); // } // } // } // Path: src/main/java/com/cdancy/artifactory/rest/features/DockerApi.java import com.cdancy.artifactory.rest.domain.docker.PromoteImage; import com.cdancy.artifactory.rest.filters.ArtifactoryAuthenticationFilter; import org.jclouds.Fallbacks; import org.jclouds.rest.annotations.*; import org.jclouds.rest.binders.BindToJsonPayload; import javax.inject.Named; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import java.util.List; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.features; @Path("/api/docker") @RequestFilters(ArtifactoryAuthenticationFilter.class) public interface DockerApi { @Named("docker:promote") @Consumes(MediaType.TEXT_PLAIN) @Path("/{repoKey}/v2/promote") @Fallback(Fallbacks.FalseOnNotFoundOr404.class) @POST
boolean promote(@PathParam("repoKey") String repoKey, @BinderParam(BindToJsonPayload.class) PromoteImage promote);
cdancy/artifactory-rest
src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryAuthentication.java // public class ArtifactoryAuthentication extends Credentials { // // private final AuthenticationType authType; // // /** // * Create instance of ArtifactoryAuthentication // * // * @param authValue value to use for authentication type HTTP header. // * @param authType authentication type (e.g. Basic, Bearer, Anonymous). // */ // private ArtifactoryAuthentication(final String authValue, final AuthenticationType authType) { // super(null, authType == AuthenticationType.Basic && authValue.contains(":") // ? base64().encode(authValue.getBytes()) // : authValue); // this.authType = authType; // } // // @Nullable // public String authValue() { // return this.credential; // } // // public AuthenticationType authType() { // return authType; // } // // public static Builder builder() { // return new Builder(); // } // // public static class Builder { // // private String authValue; // private AuthenticationType authType; // // /** // * Set 'Basic' credentials. // * // * @param basicCredentials value to use for 'Basic' credentials. // * @return this Builder. // */ // public Builder credentials(final String basicCredentials) { // this.authValue = Objects.requireNonNull(basicCredentials); // this.authType = AuthenticationType.Basic; // return this; // } // // /** // * Set 'Bearer' credentials. // * // * @param tokenCredentials value to use for 'Bearer' credentials. // * @return this Builder. // */ // public Builder token(final String tokenCredentials) { // this.authValue = Objects.requireNonNull(tokenCredentials); // this.authType = AuthenticationType.Bearer; // return this; // } // // /** // * Build and instance of ArtifactoryCredentials. // * // * @return instance of ArtifactoryCredentials. // */ // public ArtifactoryAuthentication build() { // return new ArtifactoryAuthentication(authValue, authType != null // ? authType // : AuthenticationType.Anonymous); // } // } // }
import com.cdancy.artifactory.rest.ArtifactoryAuthentication; import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; import com.google.common.net.HttpHeaders;
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.filters; @Singleton public class ArtifactoryAuthenticationFilter implements HttpRequestFilter {
// Path: src/main/java/com/cdancy/artifactory/rest/ArtifactoryAuthentication.java // public class ArtifactoryAuthentication extends Credentials { // // private final AuthenticationType authType; // // /** // * Create instance of ArtifactoryAuthentication // * // * @param authValue value to use for authentication type HTTP header. // * @param authType authentication type (e.g. Basic, Bearer, Anonymous). // */ // private ArtifactoryAuthentication(final String authValue, final AuthenticationType authType) { // super(null, authType == AuthenticationType.Basic && authValue.contains(":") // ? base64().encode(authValue.getBytes()) // : authValue); // this.authType = authType; // } // // @Nullable // public String authValue() { // return this.credential; // } // // public AuthenticationType authType() { // return authType; // } // // public static Builder builder() { // return new Builder(); // } // // public static class Builder { // // private String authValue; // private AuthenticationType authType; // // /** // * Set 'Basic' credentials. // * // * @param basicCredentials value to use for 'Basic' credentials. // * @return this Builder. // */ // public Builder credentials(final String basicCredentials) { // this.authValue = Objects.requireNonNull(basicCredentials); // this.authType = AuthenticationType.Basic; // return this; // } // // /** // * Set 'Bearer' credentials. // * // * @param tokenCredentials value to use for 'Bearer' credentials. // * @return this Builder. // */ // public Builder token(final String tokenCredentials) { // this.authValue = Objects.requireNonNull(tokenCredentials); // this.authType = AuthenticationType.Bearer; // return this; // } // // /** // * Build and instance of ArtifactoryCredentials. // * // * @return instance of ArtifactoryCredentials. // */ // public ArtifactoryAuthentication build() { // return new ArtifactoryAuthentication(authValue, authType != null // ? authType // : AuthenticationType.Anonymous); // } // } // } // Path: src/main/java/com/cdancy/artifactory/rest/filters/ArtifactoryAuthenticationFilter.java import com.cdancy.artifactory.rest.ArtifactoryAuthentication; import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; import com.google.common.net.HttpHeaders; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.cdancy.artifactory.rest.filters; @Singleton public class ArtifactoryAuthenticationFilter implements HttpRequestFilter {
private final ArtifactoryAuthentication authentication;
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/deserialization/AddressOverviewDeserializer.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/AddressOverview.java // @Data // @NoArgsConstructor // @ToString(callSuper = true) // @EqualsAndHashCode(callSuper = false) // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonDeserialize(using = AddressOverviewDeserializer.class) // public class AddressOverview extends Entity { // // private String address; // @Setter(AccessLevel.NONE) // private BigDecimal balance; // private String account; // // // public AddressOverview(String address, BigDecimal balance, String account) { // setAddress(address); // setBalance(balance); // setAccount(account); // } // // public void setBalance(BigDecimal balance) { // this.balance = balance.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); // } // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/JsonPrimitiveParser.java // public class JsonPrimitiveParser { // // public Integer parseInteger(String integerJson) { // try { // return Integer.valueOf(integerJson); // } catch (NumberFormatException e) { // return null; // } // } // // public Long parseLong(String longJson) { // try { // return Long.valueOf(longJson); // } catch (NumberFormatException e) { // return null; // } // } // // public BigInteger parseBigInteger(String bigIntegerJson) { // try { // return new BigInteger(bigIntegerJson); // } catch (NumberFormatException e) { // return null; // } // } // // public BigDecimal parseBigDecimal(String bigDecimalJson) { // try { // return new BigDecimal(bigDecimalJson).setScale(Defaults.DECIMAL_SCALE, // Defaults.ROUNDING_MODE); // } catch (NumberFormatException e) { // return null; // } // } // // public Boolean parseBoolean(String booleanJson) { // if (!booleanJson.equals(Constants.STRING_NULL)) { // return Boolean.valueOf(booleanJson); // } else { // return null; // } // } // // public String parseString(String stringJson) { // if (!stringJson.equals(Constants.STRING_NULL)) { // return unescapeJson(stringJson.replaceAll("^\"|\"$", "")); // } else { // return null; // } // } // // public String unescapeJson(String json) { // return StringEscapeUtils.unescapeJson(json); // } // }
import java.io.IOException; import java.util.ArrayList; import java.util.List; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.neemre.btcdcli4j.core.domain.AddressOverview; import com.neemre.btcdcli4j.core.jsonrpc.JsonPrimitiveParser;
package com.neemre.btcdcli4j.core.jsonrpc.deserialization; public class AddressOverviewDeserializer extends JsonDeserializer<AddressOverview> { private static final int ADDRESS_INDEX = 0; private static final int BALANCE_INDEX = 1; private static final int ACCOUNT_INDEX = 2;
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/AddressOverview.java // @Data // @NoArgsConstructor // @ToString(callSuper = true) // @EqualsAndHashCode(callSuper = false) // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonDeserialize(using = AddressOverviewDeserializer.class) // public class AddressOverview extends Entity { // // private String address; // @Setter(AccessLevel.NONE) // private BigDecimal balance; // private String account; // // // public AddressOverview(String address, BigDecimal balance, String account) { // setAddress(address); // setBalance(balance); // setAccount(account); // } // // public void setBalance(BigDecimal balance) { // this.balance = balance.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); // } // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/JsonPrimitiveParser.java // public class JsonPrimitiveParser { // // public Integer parseInteger(String integerJson) { // try { // return Integer.valueOf(integerJson); // } catch (NumberFormatException e) { // return null; // } // } // // public Long parseLong(String longJson) { // try { // return Long.valueOf(longJson); // } catch (NumberFormatException e) { // return null; // } // } // // public BigInteger parseBigInteger(String bigIntegerJson) { // try { // return new BigInteger(bigIntegerJson); // } catch (NumberFormatException e) { // return null; // } // } // // public BigDecimal parseBigDecimal(String bigDecimalJson) { // try { // return new BigDecimal(bigDecimalJson).setScale(Defaults.DECIMAL_SCALE, // Defaults.ROUNDING_MODE); // } catch (NumberFormatException e) { // return null; // } // } // // public Boolean parseBoolean(String booleanJson) { // if (!booleanJson.equals(Constants.STRING_NULL)) { // return Boolean.valueOf(booleanJson); // } else { // return null; // } // } // // public String parseString(String stringJson) { // if (!stringJson.equals(Constants.STRING_NULL)) { // return unescapeJson(stringJson.replaceAll("^\"|\"$", "")); // } else { // return null; // } // } // // public String unescapeJson(String json) { // return StringEscapeUtils.unescapeJson(json); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/deserialization/AddressOverviewDeserializer.java import java.io.IOException; import java.util.ArrayList; import java.util.List; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.neemre.btcdcli4j.core.domain.AddressOverview; import com.neemre.btcdcli4j.core.jsonrpc.JsonPrimitiveParser; package com.neemre.btcdcli4j.core.jsonrpc.deserialization; public class AddressOverviewDeserializer extends JsonDeserializer<AddressOverview> { private static final int ADDRESS_INDEX = 0; private static final int BALANCE_INDEX = 1; private static final int ACCOUNT_INDEX = 2;
private JsonPrimitiveParser parser;
priiduneemre/btcd-cli4j
daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/BlockListener.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Block.java // @Data // @NoArgsConstructor // @ToString(callSuper = true) // @EqualsAndHashCode(callSuper = false) // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class Block extends Entity { // // private String hash; // private Integer confirmations; // private Integer size; // private Integer height; // private Integer version; // @JsonProperty("merkleroot") // private String merkleRoot; // private List<String> tx; // private Long time; // private Long nonce; // private String bits; // @Setter(AccessLevel.NONE) // private BigDecimal difficulty; // @JsonProperty("chainwork") // private String chainWork; // @JsonProperty("previousblockhash") // private String previousBlockHash; // @JsonProperty("nextblockhash") // private String nextBlockHash; // // // public Block(String hash, Integer confirmations, Integer size, Integer height, Integer version, // String merkleRoot, List<String> tx, Long time, Long nonce, String bits, // BigDecimal difficulty, String chainWork, String previousBlockHash, String nextBlockHash) { // setHash(hash); // setConfirmations(confirmations); // setSize(size); // setHeight(height); // setVersion(version); // setMerkleRoot(merkleRoot); // setTx(tx); // setTime(time); // setNonce(nonce); // setBits(bits); // setDifficulty(difficulty); // setChainWork(chainWork); // setPreviousBlockHash(previousBlockHash); // setNextBlockHash(nextBlockHash); // } // // public void setDifficulty(BigDecimal difficulty) { // this.difficulty = difficulty.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); // } // }
import java.util.Observable; import java.util.Observer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import lombok.Getter; import com.neemre.btcdcli4j.core.domain.Block;
package com.neemre.btcdcli4j.daemon.event; /**An abstract adapter class for receiving {@code BLOCK} notifications. Extend this class to * override any methods of interest.*/ public abstract class BlockListener { private static final Logger LOG = LoggerFactory.getLogger(BlockListener.class); @Getter private Observer observer; public BlockListener() { observer = new Observer() { @Override public void update(Observable monitor, Object cause) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Block.java // @Data // @NoArgsConstructor // @ToString(callSuper = true) // @EqualsAndHashCode(callSuper = false) // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class Block extends Entity { // // private String hash; // private Integer confirmations; // private Integer size; // private Integer height; // private Integer version; // @JsonProperty("merkleroot") // private String merkleRoot; // private List<String> tx; // private Long time; // private Long nonce; // private String bits; // @Setter(AccessLevel.NONE) // private BigDecimal difficulty; // @JsonProperty("chainwork") // private String chainWork; // @JsonProperty("previousblockhash") // private String previousBlockHash; // @JsonProperty("nextblockhash") // private String nextBlockHash; // // // public Block(String hash, Integer confirmations, Integer size, Integer height, Integer version, // String merkleRoot, List<String> tx, Long time, Long nonce, String bits, // BigDecimal difficulty, String chainWork, String previousBlockHash, String nextBlockHash) { // setHash(hash); // setConfirmations(confirmations); // setSize(size); // setHeight(height); // setVersion(version); // setMerkleRoot(merkleRoot); // setTx(tx); // setTime(time); // setNonce(nonce); // setBits(bits); // setDifficulty(difficulty); // setChainWork(chainWork); // setPreviousBlockHash(previousBlockHash); // setNextBlockHash(nextBlockHash); // } // // public void setDifficulty(BigDecimal difficulty) { // this.difficulty = difficulty.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); // } // } // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/BlockListener.java import java.util.Observable; import java.util.Observer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import lombok.Getter; import com.neemre.btcdcli4j.core.domain.Block; package com.neemre.btcdcli4j.daemon.event; /**An abstract adapter class for receiving {@code BLOCK} notifications. Extend this class to * override any methods of interest.*/ public abstract class BlockListener { private static final Logger LOG = LoggerFactory.getLogger(BlockListener.class); @Getter private Observer observer; public BlockListener() { observer = new Observer() { @Override public void update(Observable monitor, Object cause) {
Block block = (Block)cause;
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/Network.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/NetworkTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum NetworkTypes { // // IPV4("ipv4"), // IPV6("ipv6"), // ONION("onion"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static NetworkTypes forName(String name) { // if (name != null) { // for (NetworkTypes networkType : NetworkTypes.values()) { // if (name.equals(networkType.getName())) { // return networkType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_NETWORKTYPE_UNSUPPORTED.getDescription()); // } // }
import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.domain.enums.NetworkTypes;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class Network extends Entity {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/NetworkTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum NetworkTypes { // // IPV4("ipv4"), // IPV6("ipv6"), // ONION("onion"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static NetworkTypes forName(String name) { // if (name != null) { // for (NetworkTypes networkType : NetworkTypes.values()) { // if (name.equals(networkType.getName())) { // return networkType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_NETWORKTYPE_UNSUPPORTED.getDescription()); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Network.java import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.domain.enums.NetworkTypes; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class Network extends Entity {
private NetworkTypes name;
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/WalletInfo.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class WalletInfo extends Entity { @JsonProperty("walletversion") private Integer walletVersion; @Setter(AccessLevel.NONE) private BigDecimal balance; @JsonProperty("txcount") private Integer txCount; @JsonProperty("keypoololdest") private Long keypoolOldest; @JsonProperty("keypoolsize") private Integer keypoolSize; @JsonProperty("unlocked_until") private Long unlockedUntil; public WalletInfo(Integer walletVersion, BigDecimal balance, Integer txCount, Long keypoolOldest, Integer keypoolSize, Long unlockedUntil) { setWalletVersion(walletVersion); setBalance(balance); setTxCount(txCount); setKeypoolOldest(keypoolOldest); setKeypoolSize(keypoolSize); setUnlockedUntil(unlockedUntil); } public void setBalance(BigDecimal balance) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/WalletInfo.java import java.math.BigDecimal; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class WalletInfo extends Entity { @JsonProperty("walletversion") private Integer walletVersion; @Setter(AccessLevel.NONE) private BigDecimal balance; @JsonProperty("txcount") private Integer txCount; @JsonProperty("keypoololdest") private Long keypoolOldest; @JsonProperty("keypoolsize") private Integer keypoolSize; @JsonProperty("unlocked_until") private Long unlockedUntil; public WalletInfo(Integer walletVersion, BigDecimal balance, Integer txCount, Long keypoolOldest, Integer keypoolSize, Long unlockedUntil) { setWalletVersion(walletVersion); setBalance(balance); setTxCount(txCount); setKeypoolOldest(keypoolOldest); setKeypoolSize(keypoolSize); setUnlockedUntil(unlockedUntil); } public void setBalance(BigDecimal balance) {
this.balance = balance.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/RawOutput.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class RawOutput extends Entity { @Setter(AccessLevel.NONE) private BigDecimal value; private Integer n; private PubKeyScript scriptPubKey; public RawOutput(BigDecimal value, Integer n, PubKeyScript scriptPubKey) { setValue(value); setN(n); setScriptPubKey(scriptPubKey); } public void setValue(BigDecimal value) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/RawOutput.java import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class RawOutput extends Entity { @Setter(AccessLevel.NONE) private BigDecimal value; private Integer n; private PubKeyScript scriptPubKey; public RawOutput(BigDecimal value, Integer n, PubKeyScript scriptPubKey) { setValue(value); setN(n); setScriptPubKey(scriptPubKey); } public void setValue(BigDecimal value) {
this.value = value.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/TxOutSetInfo.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults;
@JsonIgnoreProperties(ignoreUnknown = true) public class TxOutSetInfo extends Entity { private Integer height; @JsonProperty("bestblock") private String bestBlock; private Long transactions; @JsonProperty("txouts") private Long txOuts; @JsonProperty("bytes_serialized") private Long bytesSerialized; @JsonProperty("hash_serialized") private String hashSerialized; @Setter(AccessLevel.NONE) @JsonProperty("total_amount") private BigDecimal totalAmount; public TxOutSetInfo(Integer height, String bestBlock, Long transactions, Long txOuts, Long bytesSerialized, String hashSerialized, BigDecimal totalAmount) { setHeight(height); setBestBlock(bestBlock); setTransactions(transactions); setTxOuts(txOuts); setBytesSerialized(bytesSerialized); setHashSerialized(hashSerialized); setTotalAmount(totalAmount); } public void setTotalAmount(BigDecimal totalAmount) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/TxOutSetInfo.java import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; @JsonIgnoreProperties(ignoreUnknown = true) public class TxOutSetInfo extends Entity { private Integer height; @JsonProperty("bestblock") private String bestBlock; private Long transactions; @JsonProperty("txouts") private Long txOuts; @JsonProperty("bytes_serialized") private Long bytesSerialized; @JsonProperty("hash_serialized") private String hashSerialized; @Setter(AccessLevel.NONE) @JsonProperty("total_amount") private BigDecimal totalAmount; public TxOutSetInfo(Integer height, String bestBlock, Long transactions, Long txOuts, Long bytesSerialized, String hashSerialized, BigDecimal totalAmount) { setHeight(height); setBestBlock(bestBlock); setTransactions(transactions); setTxOuts(txOuts); setBytesSerialized(bytesSerialized); setHashSerialized(hashSerialized); setTotalAmount(totalAmount); } public void setTotalAmount(BigDecimal totalAmount) {
this.totalAmount = totalAmount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/Output.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.AccessLevel; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults;
public class Output extends OutputOverview { private String address; private String account; private String scriptPubKey; private String redeemScript; @Setter(AccessLevel.NONE) private BigDecimal amount; private Integer confirmations; private Boolean spendable; public Output(String txId, Integer vOut, String scriptPubKey, String redeemScript) { super(txId, vOut); this.scriptPubKey = scriptPubKey; this.redeemScript = redeemScript; } public Output(String address, String account, String scriptPubKey, String redeemScript, BigDecimal amount, Integer confirmations, Boolean spendable) { setAddress(address); setAccount(account); setScriptPubKey(scriptPubKey); setRedeemScript(redeemScript); setAmount(amount); setConfirmations(confirmations); setSpendable(spendable); } public void setAmount(BigDecimal amount) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Output.java import java.math.BigDecimal; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.AccessLevel; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults; public class Output extends OutputOverview { private String address; private String account; private String scriptPubKey; private String redeemScript; @Setter(AccessLevel.NONE) private BigDecimal amount; private Integer confirmations; private Boolean spendable; public Output(String txId, Integer vOut, String scriptPubKey, String redeemScript) { super(txId, vOut); this.scriptPubKey = scriptPubKey; this.redeemScript = redeemScript; } public Output(String address, String account, String scriptPubKey, String redeemScript, BigDecimal amount, Integer confirmations, Boolean spendable) { setAddress(address); setAccount(account); setScriptPubKey(scriptPubKey); setRedeemScript(redeemScript); setAmount(amount); setConfirmations(confirmations); setSpendable(spendable); } public void setAmount(BigDecimal amount) {
this.amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/NetworkInfo.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString;
@JsonProperty("protocolversion") private Integer protocolVersion; @JsonProperty("localservices") private String localServices; @JsonProperty("timeoffset") private Integer timeOffset; private Integer connections; private List<Network> networks; @Setter(AccessLevel.NONE) @JsonProperty("relayfee") private BigDecimal relayFee; @JsonProperty("localaddresses") private List<NetworkAddress> localAddresses; public NetworkInfo(Integer version, String subVersion, Integer protocolVersion, String localServices, Integer timeOffset, Integer connections, List<Network> networks, BigDecimal relayFee, List<NetworkAddress> localAddresses) { setVersion(version); setSubVersion(subVersion); setProtocolVersion(protocolVersion); setLocalServices(localServices); setTimeOffset(timeOffset); setConnections(connections); setNetworks(networks); setRelayFee(relayFee); setLocalAddresses(localAddresses); } public void setRelayFee(BigDecimal relayFee) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/NetworkInfo.java import java.math.BigDecimal; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; @JsonProperty("protocolversion") private Integer protocolVersion; @JsonProperty("localservices") private String localServices; @JsonProperty("timeoffset") private Integer timeOffset; private Integer connections; private List<Network> networks; @Setter(AccessLevel.NONE) @JsonProperty("relayfee") private BigDecimal relayFee; @JsonProperty("localaddresses") private List<NetworkAddress> localAddresses; public NetworkInfo(Integer version, String subVersion, Integer protocolVersion, String localServices, Integer timeOffset, Integer connections, List<Network> networks, BigDecimal relayFee, List<NetworkAddress> localAddresses) { setVersion(version); setSubVersion(subVersion); setProtocolVersion(protocolVersion); setLocalServices(localServices); setTimeOffset(timeOffset); setConnections(connections); setNetworks(networks); setRelayFee(relayFee); setLocalAddresses(localAddresses); } public void setRelayFee(BigDecimal relayFee) {
this.relayFee = relayFee.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/Transaction.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import java.util.List; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults;
@JsonProperty("timereceived") private Long timeReceived; private String comment; private String to; private List<PaymentOverview> details; private String hex; public Transaction(BigDecimal amount, BigDecimal fee, Integer confirmations, Boolean generated, String blockHash, Integer blockIndex, Long blockTime, String txId, List<String> walletConflicts, Long time, Long timeReceived, String comment, String to, List<PaymentOverview> details, String hex) { setAmount(amount); setFee(fee); setConfirmations(confirmations); setGenerated(generated); setBlockHash(blockHash); setBlockIndex(blockIndex); setBlockTime(blockTime); setTxId(txId); setWalletConflicts(walletConflicts); setTime(time); setTimeReceived(timeReceived); setComment(comment); setTo(to); setDetails(details); setHex(hex); } public void setAmount(BigDecimal amount) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Transaction.java import java.math.BigDecimal; import java.util.List; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults; @JsonProperty("timereceived") private Long timeReceived; private String comment; private String to; private List<PaymentOverview> details; private String hex; public Transaction(BigDecimal amount, BigDecimal fee, Integer confirmations, Boolean generated, String blockHash, Integer blockIndex, Long blockTime, String txId, List<String> walletConflicts, Long time, Long timeReceived, String comment, String to, List<PaymentOverview> details, String hex) { setAmount(amount); setFee(fee); setConfirmations(confirmations); setGenerated(generated); setBlockHash(blockHash); setBlockIndex(blockIndex); setBlockTime(blockTime); setTxId(txId); setWalletConflicts(walletConflicts); setTime(time); setTimeReceived(timeReceived); setComment(comment); setTo(to); setDetails(details); setHex(hex); } public void setAmount(BigDecimal amount) {
this.amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/Address.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import java.util.List; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class Address extends Entity { @JsonProperty("involvesWatchonly") private Boolean involvesWatchOnly; private String address; private String account; @Setter(AccessLevel.NONE) private BigDecimal amount; private Integer confirmations; @JsonProperty("txids") private List<String> txIds; public Address(Boolean involvesWatchOnly, String address, String account, BigDecimal amount, Integer confirmations, List<String> txIds) { setInvolvesWatchOnly(involvesWatchOnly); setAddress(address); setAccount(account); setAmount(amount); setConfirmations(confirmations); setTxIds(txIds); } public void setAmount(BigDecimal amount) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Address.java import java.math.BigDecimal; import java.util.List; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class Address extends Entity { @JsonProperty("involvesWatchonly") private Boolean involvesWatchOnly; private String address; private String account; @Setter(AccessLevel.NONE) private BigDecimal amount; private Integer confirmations; @JsonProperty("txids") private List<String> txIds; public Address(Boolean involvesWatchOnly, String address, String account, BigDecimal amount, Integer confirmations, List<String> txIds) { setInvolvesWatchOnly(involvesWatchOnly); setAddress(address); setAccount(account); setAmount(amount); setConfirmations(confirmations); setTxIds(txIds); } public void setAmount(BigDecimal amount) {
this.amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/domain/JsonRpcResponse.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/deserialization/JsonRpcResponseDeserializer.java // public class JsonRpcResponseDeserializer extends JsonDeserializer<JsonRpcResponse> { // // @Override // public JsonRpcResponse deserialize(JsonParser parser, DeserializationContext context) // throws IOException, JsonProcessingException { // RawJsonRpcResponse rawRpcResponse = parser.readValueAs(RawJsonRpcResponse.class); // // return rawRpcResponse.toJsonRpcResponse(); // } // // private static class RawJsonRpcResponse { // // public JsonNode result; // public JsonRpcError error; // public String id; // // // private JsonRpcResponse toJsonRpcResponse() { // JsonRpcResponse rpcResponse = new JsonRpcResponse(); // rpcResponse.setResult(result.toString()); // rpcResponse.setError(error); // rpcResponse.setId(id); // return rpcResponse; // } // } // }
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.neemre.btcdcli4j.core.jsonrpc.deserialization.JsonRpcResponseDeserializer; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString;
package com.neemre.btcdcli4j.core.jsonrpc.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true)
// Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/deserialization/JsonRpcResponseDeserializer.java // public class JsonRpcResponseDeserializer extends JsonDeserializer<JsonRpcResponse> { // // @Override // public JsonRpcResponse deserialize(JsonParser parser, DeserializationContext context) // throws IOException, JsonProcessingException { // RawJsonRpcResponse rawRpcResponse = parser.readValueAs(RawJsonRpcResponse.class); // // return rawRpcResponse.toJsonRpcResponse(); // } // // private static class RawJsonRpcResponse { // // public JsonNode result; // public JsonRpcError error; // public String id; // // // private JsonRpcResponse toJsonRpcResponse() { // JsonRpcResponse rpcResponse = new JsonRpcResponse(); // rpcResponse.setResult(result.toString()); // rpcResponse.setError(error); // rpcResponse.setId(id); // return rpcResponse; // } // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/domain/JsonRpcResponse.java import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.neemre.btcdcli4j.core.jsonrpc.deserialization.JsonRpcResponseDeserializer; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; package com.neemre.btcdcli4j.core.jsonrpc.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(using = JsonRpcResponseDeserializer.class)
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/Block.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString;
@Setter(AccessLevel.NONE) private BigDecimal difficulty; @JsonProperty("chainwork") private String chainWork; @JsonProperty("previousblockhash") private String previousBlockHash; @JsonProperty("nextblockhash") private String nextBlockHash; public Block(String hash, Integer confirmations, Integer size, Integer height, Integer version, String merkleRoot, List<String> tx, Long time, Long nonce, String bits, BigDecimal difficulty, String chainWork, String previousBlockHash, String nextBlockHash) { setHash(hash); setConfirmations(confirmations); setSize(size); setHeight(height); setVersion(version); setMerkleRoot(merkleRoot); setTx(tx); setTime(time); setNonce(nonce); setBits(bits); setDifficulty(difficulty); setChainWork(chainWork); setPreviousBlockHash(previousBlockHash); setNextBlockHash(nextBlockHash); } public void setDifficulty(BigDecimal difficulty) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Block.java import java.math.BigDecimal; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; @Setter(AccessLevel.NONE) private BigDecimal difficulty; @JsonProperty("chainwork") private String chainWork; @JsonProperty("previousblockhash") private String previousBlockHash; @JsonProperty("nextblockhash") private String nextBlockHash; public Block(String hash, Integer confirmations, Integer size, Integer height, Integer version, String merkleRoot, List<String> tx, Long time, Long nonce, String bits, BigDecimal difficulty, String chainWork, String previousBlockHash, String nextBlockHash) { setHash(hash); setConfirmations(confirmations); setSize(size); setHeight(height); setVersion(version); setMerkleRoot(merkleRoot); setTx(tx); setTime(time); setNonce(nonce); setBits(bits); setDifficulty(difficulty); setChainWork(chainWork); setPreviousBlockHash(previousBlockHash); setNextBlockHash(nextBlockHash); } public void setDifficulty(BigDecimal difficulty) {
this.difficulty = difficulty.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/PubKeyScript.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ScriptTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ScriptTypes { // // PUB_KEY("pubkey"), // PUB_KEY_HASH("pubkeyhash"), // SCRIPT_HASH("scripthash"), // MULTISIG("multisig"), // NULL_DATA("nulldata"), // NONSTANDARD("nonstandard"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ScriptTypes forName(String name) { // if (name != null) { // for (ScriptTypes scriptType : ScriptTypes.values()) { // if (name.equals(scriptType.getName())) { // return scriptType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_SCRIPTTYPE_UNSUPPORTED.getDescription()); // } // }
import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.domain.enums.ScriptTypes;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class PubKeyScript extends SignatureScript { private Integer reqSigs;
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ScriptTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ScriptTypes { // // PUB_KEY("pubkey"), // PUB_KEY_HASH("pubkeyhash"), // SCRIPT_HASH("scripthash"), // MULTISIG("multisig"), // NULL_DATA("nulldata"), // NONSTANDARD("nonstandard"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ScriptTypes forName(String name) { // if (name != null) { // for (ScriptTypes scriptType : ScriptTypes.values()) { // if (name.equals(scriptType.getName())) { // return scriptType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_SCRIPTTYPE_UNSUPPORTED.getDescription()); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/PubKeyScript.java import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.domain.enums.ScriptTypes; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class PubKeyScript extends SignatureScript { private Integer reqSigs;
private ScriptTypes type;
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/PeerNode.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString;
public PeerNode(Integer id, String addr, String addrLocal, String services, Long lastSend, Long lastRecv, Long bytesSent, Long bytesRecv, Long connTime, BigDecimal pingTime, BigDecimal pingWait, Integer version, String subVer, Boolean inbound, Integer startingHeight, Integer banScore, Integer syncedHeaders, Integer syncedBlocks, Boolean syncNode, List<Integer> inFlight, Boolean whitelisted) { setId(id); setAddr(addr); setAddrLocal(addrLocal); setServices(services); setLastSend(lastSend); setLastRecv(lastRecv); setBytesSent(bytesSent); setBytesRecv(bytesRecv); setConnTime(connTime); setPingTime(pingTime); setPingWait(pingWait); setVersion(version); setSubVer(subVer); setInbound(inbound); setStartingHeight(startingHeight); setBanScore(banScore); setSyncedHeaders(syncedHeaders); setSyncedBlocks(syncedBlocks); setSyncNode(syncNode); setInFlight(inFlight); setWhitelisted(whitelisted); } public void setPingTime(BigDecimal pingTime) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/PeerNode.java import java.math.BigDecimal; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; public PeerNode(Integer id, String addr, String addrLocal, String services, Long lastSend, Long lastRecv, Long bytesSent, Long bytesRecv, Long connTime, BigDecimal pingTime, BigDecimal pingWait, Integer version, String subVer, Boolean inbound, Integer startingHeight, Integer banScore, Integer syncedHeaders, Integer syncedBlocks, Boolean syncNode, List<Integer> inFlight, Boolean whitelisted) { setId(id); setAddr(addr); setAddrLocal(addrLocal); setServices(services); setLastSend(lastSend); setLastRecv(lastRecv); setBytesSent(bytesSent); setBytesRecv(bytesRecv); setConnTime(connTime); setPingTime(pingTime); setPingWait(pingWait); setVersion(version); setSubVer(subVer); setInbound(inbound); setStartingHeight(startingHeight); setBanScore(banScore); setSyncedHeaders(syncedHeaders); setSyncedBlocks(syncedBlocks); setSyncNode(syncNode); setInFlight(inFlight); setWhitelisted(whitelisted); } public void setPingTime(BigDecimal pingTime) {
this.pingTime = pingTime.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/Info.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.AccessLevel;
private BigDecimal payTxFee; @Setter(AccessLevel.NONE) @JsonProperty("relayfee") private BigDecimal relayFee; private String errors; public Info(Integer version, Integer protocolVersion, Integer walletVersion, BigDecimal balance, Integer blocks, Integer timeOffset, Integer connections, String proxy, BigDecimal difficulty, Boolean testnet, Long keypoolOldest, Integer keypoolSize, Long unlockedUntil, BigDecimal payTxFee, BigDecimal relayFee, String errors) { setVersion(version); setProtocolVersion(protocolVersion); setWalletVersion(walletVersion); setBalance(balance); setBlocks(blocks); setTimeOffset(timeOffset); setConnections(connections); setProxy(proxy); setDifficulty(difficulty); setTestnet(testnet); setKeypoolOldest(keypoolOldest); setKeypoolSize(keypoolSize); setUnlockedUntil(unlockedUntil); setPayTxFee(payTxFee); setRelayFee(relayFee); setErrors(errors); } public void setBalance(BigDecimal balance) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Info.java import java.math.BigDecimal; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.AccessLevel; private BigDecimal payTxFee; @Setter(AccessLevel.NONE) @JsonProperty("relayfee") private BigDecimal relayFee; private String errors; public Info(Integer version, Integer protocolVersion, Integer walletVersion, BigDecimal balance, Integer blocks, Integer timeOffset, Integer connections, String proxy, BigDecimal difficulty, Boolean testnet, Long keypoolOldest, Integer keypoolSize, Long unlockedUntil, BigDecimal payTxFee, BigDecimal relayFee, String errors) { setVersion(version); setProtocolVersion(protocolVersion); setWalletVersion(walletVersion); setBalance(balance); setBlocks(blocks); setTimeOffset(timeOffset); setConnections(connections); setProxy(proxy); setDifficulty(difficulty); setTestnet(testnet); setKeypoolOldest(keypoolOldest); setKeypoolSize(keypoolSize); setUnlockedUntil(unlockedUntil); setPayTxFee(payTxFee); setRelayFee(relayFee); setErrors(errors); } public void setBalance(BigDecimal balance) {
this.balance = balance.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/PeerNodeOverview.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ConnectionTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ConnectionTypes { // // FALSE("false"), // INBOUND("inbound"), // OUTBOUND("outbound"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ConnectionTypes forName(String name) { // if (name != null) { // for (ConnectionTypes connectionType : ConnectionTypes.values()) { // if (name.equals(connectionType.getName())) { // return connectionType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CONNECTIONTYPE_UNSUPPORTED.getDescription()); // } // }
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.domain.enums.ConnectionTypes; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class PeerNodeOverview extends Entity { private String address;
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ConnectionTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ConnectionTypes { // // FALSE("false"), // INBOUND("inbound"), // OUTBOUND("outbound"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ConnectionTypes forName(String name) { // if (name != null) { // for (ConnectionTypes connectionType : ConnectionTypes.values()) { // if (name.equals(connectionType.getName())) { // return connectionType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CONNECTIONTYPE_UNSUPPORTED.getDescription()); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/PeerNodeOverview.java import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.domain.enums.ConnectionTypes; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class PeerNodeOverview extends Entity { private String address;
private ConnectionTypes connected;
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/util/CollectionUtils.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Errors.java // @Getter // @ToString // @AllArgsConstructor // public enum Errors { // // ARGS_COUNT_UNEVEN(1001001, "Expected the argument count to be 'even', but was 'uneven' instead."), // ARGS_COUNT_UNEQUAL(1001002, "Expected the argument count to be 'equal', but was 'unequal' instead."), // ARGS_VALUE_NEGATIVE(1001003, "Expected the argument value to be positive (>=0), but was negative (<0) " // + "instead."), // ARGS_NULL(1001004, "Expected a non-null argument, but got 'null' instead."), // ARGS_CONTAIN_NULL(1001005, "Expected only non-null arguments, but got >0 'null' instead."), // ARGS_HTTP_METHOD_UNSUPPORTED(1001006, "Expected the argument to be a valid HTTP method, but was " // + "invalid/unsupported instead."), // ARGS_HTTP_AUTHSCHEME_UNSUPPORTED(1001007, "Expected the argument to be a valid HTTP auth scheme, but " // + "was invalid/unsupported instead."), // ARGS_BTCD_BLOCKSTATUS_UNSUPPORTED(1001008, "Expected the argument to be a valid 'bitcoind' block status, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_CHAINSTATUS_UNSUPPORTED(1001009, "Expected the argument to be a valid 'bitcoind' chain status, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_CHAINTYPE_UNSUPPORTED(1001010, "Expected the argument to be a valid 'bitcoind' chain type, but " // + "was invalid/unsupported instead."), // ARGS_BTCD_CHECKLEVEL_UNSUPPORTED(1001011, "Expected the argument to be a valid 'bitcoind' check level, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_CONNECTIONTYPE_UNSUPPORTED(1001012, "Expected the argument to be a valid 'bitcoind' connection " // + "type, but was invalid/unsupported instead."), // ARGS_BTCD_NETWORKTYPE_UNSUPPORTED(1001013, "Expected the argument to be a valid 'bitcoind' network type, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_PAYMENTCATEGORY_UNSUPPORTED(1001014, "Expected the argument to be a valid 'bitcoind' payment " // + "category, but was invalid/unsupported instead."), // ARGS_BTCD_PEERCONTROL_UNSUPPORTED(1001015, "Expected the argument to be a valid 'bitcoind' peer control, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_SCRIPTTYPE_UNSUPPORTED(1001016, "Expected the argument to be a valid 'bitcoind' script type, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_SIGHASHTYPE_UNSUPPORTED(1001017, "Expected the argument to be a valid 'bitcoind' signature hash " // + "type, but was invalid/unsupported instead."), // ARGS_BTCD_NOTIFICATION_UNSUPPORTED(1001018, "Expected the argument to be a valid 'bitcoind' notification " // + "type, but was invalid/unsupported instead."), // ARGS_BTCD_PROVIDER_NULL(1001019, "Expected a preconfigured 'bitcoind' JSON-RPC API provider, but got " // + "'null' instead."), // REQUEST_HTTP_FAULT(1002001, "Request execution failed due an error in the HTTP protocol."), // RESPONSE_HTTP_CLIENT_FAULT(1003001, "The server responded with a non-OK (4xx) HTTP status code. " // + "Status line: "), // RESPONSE_HTTP_SERVER_FAULT(1003002, "The server responded with a non-OK (5xx) HTTP status code. " // + "Status line: "), // RESPONSE_JSONRPC_NULL(1003003, "Expected a non-null JSON-RPC response object, but got 'null' instead."), // RESPONSE_JSONRPC_NULL_ID(1003004, "Expected a non-null JSON-RPC response id, but got 'null' instead."), // RESPONSE_JSONRPC_UNEQUAL_IDS(1003005, "Expected the JSON-RPC request and response ids to be 'equal', " // + "but were 'unequal' instead."), // IO_STREAM_UNCLOSED(1004001, "Unable to close the specified stream."), // IO_SOCKET_UNINITIALIZED(1004002, "Unable to open the specified socket."), // IO_SERVERSOCKET_UNINITIALIZED(1004003, "Unable to open the specified server socket."), // IO_UNKNOWN(1004004, "The operation failed due to an unknown IO exception."), // PARSE_URI_FAILED(1005001, "Unable to parse the specified URI."), // PARSE_JSON_UNKNOWN(1005002, "An unknown exception occurred while parsing/generating JSON content."), // PARSE_JSON_MALFORMED(1005003, "Unable to parse the specified JSON content (malformed syntax detected)."), // MAP_JSON_UNKNOWN(1006001, "An unknown exception ocurred while mapping the JSON content."); // // private final int code; // private final String message; // // // public String getDescription() { // return String.format("Error #%s: %s", code, message); // } // }
import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import lombok.AccessLevel; import lombok.NoArgsConstructor; import com.neemre.btcdcli4j.core.common.Errors;
package com.neemre.btcdcli4j.core.util; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class CollectionUtils { public static List<Object> asList(Object... items) { List<Object> itemsList = new ArrayList<Object>(items.length); for (Object item : items) { itemsList.add(item); } return itemsList; } public static Map<Object, Object> asMap(Object... items) { if (!NumberUtils.isEven(items.length)) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Errors.java // @Getter // @ToString // @AllArgsConstructor // public enum Errors { // // ARGS_COUNT_UNEVEN(1001001, "Expected the argument count to be 'even', but was 'uneven' instead."), // ARGS_COUNT_UNEQUAL(1001002, "Expected the argument count to be 'equal', but was 'unequal' instead."), // ARGS_VALUE_NEGATIVE(1001003, "Expected the argument value to be positive (>=0), but was negative (<0) " // + "instead."), // ARGS_NULL(1001004, "Expected a non-null argument, but got 'null' instead."), // ARGS_CONTAIN_NULL(1001005, "Expected only non-null arguments, but got >0 'null' instead."), // ARGS_HTTP_METHOD_UNSUPPORTED(1001006, "Expected the argument to be a valid HTTP method, but was " // + "invalid/unsupported instead."), // ARGS_HTTP_AUTHSCHEME_UNSUPPORTED(1001007, "Expected the argument to be a valid HTTP auth scheme, but " // + "was invalid/unsupported instead."), // ARGS_BTCD_BLOCKSTATUS_UNSUPPORTED(1001008, "Expected the argument to be a valid 'bitcoind' block status, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_CHAINSTATUS_UNSUPPORTED(1001009, "Expected the argument to be a valid 'bitcoind' chain status, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_CHAINTYPE_UNSUPPORTED(1001010, "Expected the argument to be a valid 'bitcoind' chain type, but " // + "was invalid/unsupported instead."), // ARGS_BTCD_CHECKLEVEL_UNSUPPORTED(1001011, "Expected the argument to be a valid 'bitcoind' check level, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_CONNECTIONTYPE_UNSUPPORTED(1001012, "Expected the argument to be a valid 'bitcoind' connection " // + "type, but was invalid/unsupported instead."), // ARGS_BTCD_NETWORKTYPE_UNSUPPORTED(1001013, "Expected the argument to be a valid 'bitcoind' network type, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_PAYMENTCATEGORY_UNSUPPORTED(1001014, "Expected the argument to be a valid 'bitcoind' payment " // + "category, but was invalid/unsupported instead."), // ARGS_BTCD_PEERCONTROL_UNSUPPORTED(1001015, "Expected the argument to be a valid 'bitcoind' peer control, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_SCRIPTTYPE_UNSUPPORTED(1001016, "Expected the argument to be a valid 'bitcoind' script type, " // + "but was invalid/unsupported instead."), // ARGS_BTCD_SIGHASHTYPE_UNSUPPORTED(1001017, "Expected the argument to be a valid 'bitcoind' signature hash " // + "type, but was invalid/unsupported instead."), // ARGS_BTCD_NOTIFICATION_UNSUPPORTED(1001018, "Expected the argument to be a valid 'bitcoind' notification " // + "type, but was invalid/unsupported instead."), // ARGS_BTCD_PROVIDER_NULL(1001019, "Expected a preconfigured 'bitcoind' JSON-RPC API provider, but got " // + "'null' instead."), // REQUEST_HTTP_FAULT(1002001, "Request execution failed due an error in the HTTP protocol."), // RESPONSE_HTTP_CLIENT_FAULT(1003001, "The server responded with a non-OK (4xx) HTTP status code. " // + "Status line: "), // RESPONSE_HTTP_SERVER_FAULT(1003002, "The server responded with a non-OK (5xx) HTTP status code. " // + "Status line: "), // RESPONSE_JSONRPC_NULL(1003003, "Expected a non-null JSON-RPC response object, but got 'null' instead."), // RESPONSE_JSONRPC_NULL_ID(1003004, "Expected a non-null JSON-RPC response id, but got 'null' instead."), // RESPONSE_JSONRPC_UNEQUAL_IDS(1003005, "Expected the JSON-RPC request and response ids to be 'equal', " // + "but were 'unequal' instead."), // IO_STREAM_UNCLOSED(1004001, "Unable to close the specified stream."), // IO_SOCKET_UNINITIALIZED(1004002, "Unable to open the specified socket."), // IO_SERVERSOCKET_UNINITIALIZED(1004003, "Unable to open the specified server socket."), // IO_UNKNOWN(1004004, "The operation failed due to an unknown IO exception."), // PARSE_URI_FAILED(1005001, "Unable to parse the specified URI."), // PARSE_JSON_UNKNOWN(1005002, "An unknown exception occurred while parsing/generating JSON content."), // PARSE_JSON_MALFORMED(1005003, "Unable to parse the specified JSON content (malformed syntax detected)."), // MAP_JSON_UNKNOWN(1006001, "An unknown exception ocurred while mapping the JSON content."); // // private final int code; // private final String message; // // // public String getDescription() { // return String.format("Error #%s: %s", code, message); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/util/CollectionUtils.java import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import lombok.AccessLevel; import lombok.NoArgsConstructor; import com.neemre.btcdcli4j.core.common.Errors; package com.neemre.btcdcli4j.core.util; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class CollectionUtils { public static List<Object> asList(Object... items) { List<Object> itemsList = new ArrayList<Object>(items.length); for (Object item : items) { itemsList.add(item); } return itemsList; } public static Map<Object, Object> asMap(Object... items) { if (!NumberUtils.isEven(items.length)) {
throw new IllegalArgumentException(Errors.ARGS_COUNT_UNEVEN.getDescription());
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/AddressOverview.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/deserialization/AddressOverviewDeserializer.java // public class AddressOverviewDeserializer extends JsonDeserializer<AddressOverview> { // // private static final int ADDRESS_INDEX = 0; // private static final int BALANCE_INDEX = 1; // private static final int ACCOUNT_INDEX = 2; // // private JsonPrimitiveParser parser; // // // public AddressOverviewDeserializer() { // parser = new JsonPrimitiveParser(); // } // // @Override // public AddressOverview deserialize(JsonParser parser, DeserializationContext context) // throws IOException, JsonProcessingException { // List<Object> propertyList = context.readValue(parser, context.getTypeFactory() // .constructCollectionType(ArrayList.class, Object.class)); // return toAddressOverview(propertyList); // } // // private AddressOverview toAddressOverview(List<Object> propertyList) { // AddressOverview addressOverview = new AddressOverview(); // addressOverview.setAddress(parser.parseString(propertyList.get(ADDRESS_INDEX).toString())); // addressOverview.setBalance(parser.parseBigDecimal(propertyList.get(BALANCE_INDEX).toString())); // addressOverview.setAccount(parser.parseString(propertyList.get(ACCOUNT_INDEX).toString())); // return addressOverview; // } // }
import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.jsonrpc.deserialization.AddressOverviewDeserializer;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true)
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/deserialization/AddressOverviewDeserializer.java // public class AddressOverviewDeserializer extends JsonDeserializer<AddressOverview> { // // private static final int ADDRESS_INDEX = 0; // private static final int BALANCE_INDEX = 1; // private static final int ACCOUNT_INDEX = 2; // // private JsonPrimitiveParser parser; // // // public AddressOverviewDeserializer() { // parser = new JsonPrimitiveParser(); // } // // @Override // public AddressOverview deserialize(JsonParser parser, DeserializationContext context) // throws IOException, JsonProcessingException { // List<Object> propertyList = context.readValue(parser, context.getTypeFactory() // .constructCollectionType(ArrayList.class, Object.class)); // return toAddressOverview(propertyList); // } // // private AddressOverview toAddressOverview(List<Object> propertyList) { // AddressOverview addressOverview = new AddressOverview(); // addressOverview.setAddress(parser.parseString(propertyList.get(ADDRESS_INDEX).toString())); // addressOverview.setBalance(parser.parseBigDecimal(propertyList.get(BALANCE_INDEX).toString())); // addressOverview.setAccount(parser.parseString(propertyList.get(ACCOUNT_INDEX).toString())); // return addressOverview; // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/AddressOverview.java import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.jsonrpc.deserialization.AddressOverviewDeserializer; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(using = AddressOverviewDeserializer.class)
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/AddressOverview.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/deserialization/AddressOverviewDeserializer.java // public class AddressOverviewDeserializer extends JsonDeserializer<AddressOverview> { // // private static final int ADDRESS_INDEX = 0; // private static final int BALANCE_INDEX = 1; // private static final int ACCOUNT_INDEX = 2; // // private JsonPrimitiveParser parser; // // // public AddressOverviewDeserializer() { // parser = new JsonPrimitiveParser(); // } // // @Override // public AddressOverview deserialize(JsonParser parser, DeserializationContext context) // throws IOException, JsonProcessingException { // List<Object> propertyList = context.readValue(parser, context.getTypeFactory() // .constructCollectionType(ArrayList.class, Object.class)); // return toAddressOverview(propertyList); // } // // private AddressOverview toAddressOverview(List<Object> propertyList) { // AddressOverview addressOverview = new AddressOverview(); // addressOverview.setAddress(parser.parseString(propertyList.get(ADDRESS_INDEX).toString())); // addressOverview.setBalance(parser.parseBigDecimal(propertyList.get(BALANCE_INDEX).toString())); // addressOverview.setAccount(parser.parseString(propertyList.get(ACCOUNT_INDEX).toString())); // return addressOverview; // } // }
import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.jsonrpc.deserialization.AddressOverviewDeserializer;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(using = AddressOverviewDeserializer.class) public class AddressOverview extends Entity { private String address; @Setter(AccessLevel.NONE) private BigDecimal balance; private String account; public AddressOverview(String address, BigDecimal balance, String account) { setAddress(address); setBalance(balance); setAccount(account); } public void setBalance(BigDecimal balance) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/deserialization/AddressOverviewDeserializer.java // public class AddressOverviewDeserializer extends JsonDeserializer<AddressOverview> { // // private static final int ADDRESS_INDEX = 0; // private static final int BALANCE_INDEX = 1; // private static final int ACCOUNT_INDEX = 2; // // private JsonPrimitiveParser parser; // // // public AddressOverviewDeserializer() { // parser = new JsonPrimitiveParser(); // } // // @Override // public AddressOverview deserialize(JsonParser parser, DeserializationContext context) // throws IOException, JsonProcessingException { // List<Object> propertyList = context.readValue(parser, context.getTypeFactory() // .constructCollectionType(ArrayList.class, Object.class)); // return toAddressOverview(propertyList); // } // // private AddressOverview toAddressOverview(List<Object> propertyList) { // AddressOverview addressOverview = new AddressOverview(); // addressOverview.setAddress(parser.parseString(propertyList.get(ADDRESS_INDEX).toString())); // addressOverview.setBalance(parser.parseBigDecimal(propertyList.get(BALANCE_INDEX).toString())); // addressOverview.setAccount(parser.parseString(propertyList.get(ACCOUNT_INDEX).toString())); // return addressOverview; // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/AddressOverview.java import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.jsonrpc.deserialization.AddressOverviewDeserializer; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(using = AddressOverviewDeserializer.class) public class AddressOverview extends Entity { private String address; @Setter(AccessLevel.NONE) private BigDecimal balance; private String account; public AddressOverview(String address, BigDecimal balance, String account) { setAddress(address); setBalance(balance); setAccount(account); } public void setBalance(BigDecimal balance) {
this.balance = balance.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
examples/src/main/java/com/neemre/btcdcli4j/examples/util/OutputUtils.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/util/CollectionUtils.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class CollectionUtils { // // public static List<Object> asList(Object... items) { // List<Object> itemsList = new ArrayList<Object>(items.length); // for (Object item : items) { // itemsList.add(item); // } // return itemsList; // } // // public static Map<Object, Object> asMap(Object... items) { // if (!NumberUtils.isEven(items.length)) { // throw new IllegalArgumentException(Errors.ARGS_COUNT_UNEVEN.getDescription()); // } // Map<Object, Object> pairsMap = new HashMap<Object, Object>(items.length / 2); // for (int i = 0; i < items.length; i = i + 2) { // pairsMap.put(items[i], items[i + 1]); // } // return pairsMap; // } // // @SafeVarargs // public static List<Object> merge(List<? extends Object>... lists) { // if (containsNull(lists)) { // throw new IllegalArgumentException(Errors.ARGS_CONTAIN_NULL.getDescription()); // } // List<Object> mergedList = new ArrayList<Object>(); // for (List<? extends Object> list : lists) { // mergedList.addAll(list); // } // return mergedList; // } // // @SafeVarargs // public static List<Object> mergeInterlaced(List<? extends Object>... lists) { // if (containsNull(lists)) { // throw new IllegalArgumentException(Errors.ARGS_CONTAIN_NULL.getDescription()); // } // if (!equalsSize(lists)) { // throw new IllegalArgumentException(Errors.ARGS_COUNT_UNEQUAL.getDescription()); // } // List<Object> mergedList = new ArrayList<Object>(); // if (lists.length > 0) { // for (int i = 0; i < lists[0].size(); i++) { // for (List<? extends Object> list : lists) { // mergedList.add(list.get(i)); // } // } // } // return mergedList; // } // // @SafeVarargs // public static boolean equalsSize(List<? extends Object>... lists) { // Set<Integer> sizes = new HashSet<Integer>(lists.length); // for (List<? extends Object> list : lists) { // if (list == null) { // return false; // } // if (sizes.isEmpty()) { // sizes.add(list.size()); // } else { // if (sizes.add(list.size())) { // return false; // } // } // } // return true; // } // // public static Object[] asLists(Object[]... arrays) { // if (containsNull(arrays)) { // throw new IllegalArgumentException(Errors.ARGS_CONTAIN_NULL.getDescription()); // } // Object[] lists = new Object[arrays.length]; // for (int i = 0; i < arrays.length; i++) { // lists[i] = Arrays.asList(arrays[i]); // } // return lists; // } // // public static boolean containsNull(Object[]... arrays) { // for (Object[] array : arrays) { // if (array == null) { // return true; // } // } // return false; // } // // @SafeVarargs // public static boolean containsNull(List<? extends Object>... lists) { // for (List<? extends Object> list : lists) { // if (list == null) { // return true; // } // } // return false; // } // // public static <T> List<T> duplicate(T reference, int count) { // List<T> references = new ArrayList<T>(); // for (int i = 0; i < count; i++) { // references.add(reference); // } // return references; // } // }
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import lombok.NoArgsConstructor; import lombok.AccessLevel; import org.apache.commons.lang3.StringUtils; import com.neemre.btcdcli4j.core.util.CollectionUtils;
package com.neemre.btcdcli4j.examples.util; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class OutputUtils { private static final int LINE_SEPARATOR_LENGTH = 89; public static void printResult(String methodName, String[] paramNames, Object[] paramValues, Object result) { List<Object> printables = new ArrayList<Object>(); printables.add(methodName); if (!(paramNames == null || paramValues == null)) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/util/CollectionUtils.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class CollectionUtils { // // public static List<Object> asList(Object... items) { // List<Object> itemsList = new ArrayList<Object>(items.length); // for (Object item : items) { // itemsList.add(item); // } // return itemsList; // } // // public static Map<Object, Object> asMap(Object... items) { // if (!NumberUtils.isEven(items.length)) { // throw new IllegalArgumentException(Errors.ARGS_COUNT_UNEVEN.getDescription()); // } // Map<Object, Object> pairsMap = new HashMap<Object, Object>(items.length / 2); // for (int i = 0; i < items.length; i = i + 2) { // pairsMap.put(items[i], items[i + 1]); // } // return pairsMap; // } // // @SafeVarargs // public static List<Object> merge(List<? extends Object>... lists) { // if (containsNull(lists)) { // throw new IllegalArgumentException(Errors.ARGS_CONTAIN_NULL.getDescription()); // } // List<Object> mergedList = new ArrayList<Object>(); // for (List<? extends Object> list : lists) { // mergedList.addAll(list); // } // return mergedList; // } // // @SafeVarargs // public static List<Object> mergeInterlaced(List<? extends Object>... lists) { // if (containsNull(lists)) { // throw new IllegalArgumentException(Errors.ARGS_CONTAIN_NULL.getDescription()); // } // if (!equalsSize(lists)) { // throw new IllegalArgumentException(Errors.ARGS_COUNT_UNEQUAL.getDescription()); // } // List<Object> mergedList = new ArrayList<Object>(); // if (lists.length > 0) { // for (int i = 0; i < lists[0].size(); i++) { // for (List<? extends Object> list : lists) { // mergedList.add(list.get(i)); // } // } // } // return mergedList; // } // // @SafeVarargs // public static boolean equalsSize(List<? extends Object>... lists) { // Set<Integer> sizes = new HashSet<Integer>(lists.length); // for (List<? extends Object> list : lists) { // if (list == null) { // return false; // } // if (sizes.isEmpty()) { // sizes.add(list.size()); // } else { // if (sizes.add(list.size())) { // return false; // } // } // } // return true; // } // // public static Object[] asLists(Object[]... arrays) { // if (containsNull(arrays)) { // throw new IllegalArgumentException(Errors.ARGS_CONTAIN_NULL.getDescription()); // } // Object[] lists = new Object[arrays.length]; // for (int i = 0; i < arrays.length; i++) { // lists[i] = Arrays.asList(arrays[i]); // } // return lists; // } // // public static boolean containsNull(Object[]... arrays) { // for (Object[] array : arrays) { // if (array == null) { // return true; // } // } // return false; // } // // @SafeVarargs // public static boolean containsNull(List<? extends Object>... lists) { // for (List<? extends Object> list : lists) { // if (list == null) { // return true; // } // } // return false; // } // // public static <T> List<T> duplicate(T reference, int count) { // List<T> references = new ArrayList<T>(); // for (int i = 0; i < count; i++) { // references.add(reference); // } // return references; // } // } // Path: examples/src/main/java/com/neemre/btcdcli4j/examples/util/OutputUtils.java import java.util.ArrayList; import java.util.Arrays; import java.util.List; import lombok.NoArgsConstructor; import lombok.AccessLevel; import org.apache.commons.lang3.StringUtils; import com.neemre.btcdcli4j.core.util.CollectionUtils; package com.neemre.btcdcli4j.examples.util; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class OutputUtils { private static final int LINE_SEPARATOR_LENGTH = 89; public static void printResult(String methodName, String[] paramNames, Object[] paramValues, Object result) { List<Object> printables = new ArrayList<Object>(); printables.add(methodName); if (!(paramNames == null || paramValues == null)) {
printables.addAll(CollectionUtils.mergeInterlaced(Arrays.asList(paramNames),
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/MiningInfo.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ChainTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ChainTypes { // // MAINNET("main"), // TESTNET("test"), // REGTEST("regtest"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ChainTypes forName(String name) { // if (name != null) { // for (ChainTypes chainType : ChainTypes.values()) { // if (name.equals(chainType.getName())) { // return chainType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CHAINTYPE_UNSUPPORTED.getDescription()); // } // }
import java.math.BigDecimal; import java.math.BigInteger; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.ChainTypes;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class MiningInfo extends Entity { private Integer blocks; @JsonProperty("currentblocksize") private Integer currentBlockSize; @JsonProperty("currentblocktx") private Integer currentBlockTx; @Setter(AccessLevel.NONE) private BigDecimal difficulty; private String errors; @JsonProperty("genproclimit") private Integer genProcLimit; @JsonProperty("networkhashps") private BigInteger networkHashPs; @JsonProperty("pooledtx") private Integer pooledTx; private Boolean testnet;
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ChainTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ChainTypes { // // MAINNET("main"), // TESTNET("test"), // REGTEST("regtest"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ChainTypes forName(String name) { // if (name != null) { // for (ChainTypes chainType : ChainTypes.values()) { // if (name.equals(chainType.getName())) { // return chainType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CHAINTYPE_UNSUPPORTED.getDescription()); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/MiningInfo.java import java.math.BigDecimal; import java.math.BigInteger; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.ChainTypes; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class MiningInfo extends Entity { private Integer blocks; @JsonProperty("currentblocksize") private Integer currentBlockSize; @JsonProperty("currentblocktx") private Integer currentBlockTx; @Setter(AccessLevel.NONE) private BigDecimal difficulty; private String errors; @JsonProperty("genproclimit") private Integer genProcLimit; @JsonProperty("networkhashps") private BigInteger networkHashPs; @JsonProperty("pooledtx") private Integer pooledTx; private Boolean testnet;
private ChainTypes chain;
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/MiningInfo.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ChainTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ChainTypes { // // MAINNET("main"), // TESTNET("test"), // REGTEST("regtest"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ChainTypes forName(String name) { // if (name != null) { // for (ChainTypes chainType : ChainTypes.values()) { // if (name.equals(chainType.getName())) { // return chainType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CHAINTYPE_UNSUPPORTED.getDescription()); // } // }
import java.math.BigDecimal; import java.math.BigInteger; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.ChainTypes;
@JsonProperty("networkhashps") private BigInteger networkHashPs; @JsonProperty("pooledtx") private Integer pooledTx; private Boolean testnet; private ChainTypes chain; private Boolean generate; @JsonProperty("hashespersec") private Long hashesPerSec; public MiningInfo(Integer blocks, Integer currentBlockSize, Integer currentBlockTx, BigDecimal difficulty, String errors, Integer genProcLimit, BigInteger networkHashPs, Integer pooledTx, Boolean testnet, ChainTypes chain, Boolean generate, Long hashesPerSec) { setBlocks(blocks); setCurrentBlockSize(currentBlockSize); setCurrentBlockTx(currentBlockTx); setDifficulty(difficulty); setErrors(errors); setGenProcLimit(genProcLimit); setNetworkHashPs(networkHashPs); setPooledTx(pooledTx); setTestnet(testnet); setChain(chain); setGenerate(generate); setHashesPerSec(hashesPerSec); } public void setDifficulty(BigDecimal difficulty) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ChainTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ChainTypes { // // MAINNET("main"), // TESTNET("test"), // REGTEST("regtest"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ChainTypes forName(String name) { // if (name != null) { // for (ChainTypes chainType : ChainTypes.values()) { // if (name.equals(chainType.getName())) { // return chainType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CHAINTYPE_UNSUPPORTED.getDescription()); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/MiningInfo.java import java.math.BigDecimal; import java.math.BigInteger; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.ChainTypes; @JsonProperty("networkhashps") private BigInteger networkHashPs; @JsonProperty("pooledtx") private Integer pooledTx; private Boolean testnet; private ChainTypes chain; private Boolean generate; @JsonProperty("hashespersec") private Long hashesPerSec; public MiningInfo(Integer blocks, Integer currentBlockSize, Integer currentBlockTx, BigDecimal difficulty, String errors, Integer genProcLimit, BigInteger networkHashPs, Integer pooledTx, Boolean testnet, ChainTypes chain, Boolean generate, Long hashesPerSec) { setBlocks(blocks); setCurrentBlockSize(currentBlockSize); setCurrentBlockTx(currentBlockTx); setDifficulty(difficulty); setErrors(errors); setGenProcLimit(genProcLimit); setNetworkHashPs(networkHashPs); setPooledTx(pooledTx); setTestnet(testnet); setChain(chain); setGenerate(generate); setHashesPerSec(hashesPerSec); } public void setDifficulty(BigDecimal difficulty) {
this.difficulty = difficulty.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/AddressInfo.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ScriptTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ScriptTypes { // // PUB_KEY("pubkey"), // PUB_KEY_HASH("pubkeyhash"), // SCRIPT_HASH("scripthash"), // MULTISIG("multisig"), // NULL_DATA("nulldata"), // NONSTANDARD("nonstandard"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ScriptTypes forName(String name) { // if (name != null) { // for (ScriptTypes scriptType : ScriptTypes.values()) { // if (name.equals(scriptType.getName())) { // return scriptType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_SCRIPTTYPE_UNSUPPORTED.getDescription()); // } // }
import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.domain.enums.ScriptTypes;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class AddressInfo extends Entity { @JsonProperty("isvalid") private Boolean isValid; private String address; @JsonProperty("ismine") private Boolean isMine; @JsonProperty("iswatchonly") private Boolean isWatchOnly; @JsonProperty("isscript") private Boolean isScript;
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ScriptTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ScriptTypes { // // PUB_KEY("pubkey"), // PUB_KEY_HASH("pubkeyhash"), // SCRIPT_HASH("scripthash"), // MULTISIG("multisig"), // NULL_DATA("nulldata"), // NONSTANDARD("nonstandard"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ScriptTypes forName(String name) { // if (name != null) { // for (ScriptTypes scriptType : ScriptTypes.values()) { // if (name.equals(scriptType.getName())) { // return scriptType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_SCRIPTTYPE_UNSUPPORTED.getDescription()); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/AddressInfo.java import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.domain.enums.ScriptTypes; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class AddressInfo extends Entity { @JsonProperty("isvalid") private Boolean isValid; private String address; @JsonProperty("ismine") private Boolean isMine; @JsonProperty("iswatchonly") private Boolean isWatchOnly; @JsonProperty("isscript") private Boolean isScript;
private ScriptTypes script;
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/PaymentOverview.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/PaymentCategories.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum PaymentCategories { // // SEND("send"), // RECEIVE("receive"), // GENERATE("generate"), // IMMATURE("immature"), // ORPHAN("orphan"), // MOVE("move"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static PaymentCategories forName(String name) { // if (name != null) { // for (PaymentCategories paymentCategory : PaymentCategories.values()) { // if (name.equals(paymentCategory.getName())) { // return paymentCategory; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_PAYMENTCATEGORY_UNSUPPORTED.getDescription()); // } // }
import java.math.BigDecimal; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.AccessLevel; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.PaymentCategories;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class PaymentOverview extends Entity { @JsonProperty("involvesWatchonly") public Boolean involvesWatchOnly; private String account; private String address;
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/PaymentCategories.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum PaymentCategories { // // SEND("send"), // RECEIVE("receive"), // GENERATE("generate"), // IMMATURE("immature"), // ORPHAN("orphan"), // MOVE("move"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static PaymentCategories forName(String name) { // if (name != null) { // for (PaymentCategories paymentCategory : PaymentCategories.values()) { // if (name.equals(paymentCategory.getName())) { // return paymentCategory; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_PAYMENTCATEGORY_UNSUPPORTED.getDescription()); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/PaymentOverview.java import java.math.BigDecimal; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.AccessLevel; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.PaymentCategories; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class PaymentOverview extends Entity { @JsonProperty("involvesWatchonly") public Boolean involvesWatchOnly; private String account; private String address;
private PaymentCategories category;
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/PaymentOverview.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/PaymentCategories.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum PaymentCategories { // // SEND("send"), // RECEIVE("receive"), // GENERATE("generate"), // IMMATURE("immature"), // ORPHAN("orphan"), // MOVE("move"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static PaymentCategories forName(String name) { // if (name != null) { // for (PaymentCategories paymentCategory : PaymentCategories.values()) { // if (name.equals(paymentCategory.getName())) { // return paymentCategory; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_PAYMENTCATEGORY_UNSUPPORTED.getDescription()); // } // }
import java.math.BigDecimal; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.AccessLevel; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.PaymentCategories;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class PaymentOverview extends Entity { @JsonProperty("involvesWatchonly") public Boolean involvesWatchOnly; private String account; private String address; private PaymentCategories category; @Setter(AccessLevel.NONE) private BigDecimal amount; @JsonProperty("vout") private Integer vOut; @Setter(AccessLevel.NONE) private BigDecimal fee; public PaymentOverview(Boolean involvesWatchOnly, String account, String address, PaymentCategories category, BigDecimal amount, Integer vOut, BigDecimal fee) { setInvolvesWatchOnly(involvesWatchOnly); setAccount(account); setAddress(address); setCategory(category); setAmount(amount); setVOut(vOut); setFee(fee); } public void setAmount(BigDecimal amount) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/PaymentCategories.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum PaymentCategories { // // SEND("send"), // RECEIVE("receive"), // GENERATE("generate"), // IMMATURE("immature"), // ORPHAN("orphan"), // MOVE("move"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static PaymentCategories forName(String name) { // if (name != null) { // for (PaymentCategories paymentCategory : PaymentCategories.values()) { // if (name.equals(paymentCategory.getName())) { // return paymentCategory; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_PAYMENTCATEGORY_UNSUPPORTED.getDescription()); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/PaymentOverview.java import java.math.BigDecimal; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.AccessLevel; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.PaymentCategories; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class PaymentOverview extends Entity { @JsonProperty("involvesWatchonly") public Boolean involvesWatchOnly; private String account; private String address; private PaymentCategories category; @Setter(AccessLevel.NONE) private BigDecimal amount; @JsonProperty("vout") private Integer vOut; @Setter(AccessLevel.NONE) private BigDecimal fee; public PaymentOverview(Boolean involvesWatchOnly, String account, String address, PaymentCategories category, BigDecimal amount, Integer vOut, BigDecimal fee) { setInvolvesWatchOnly(involvesWatchOnly); setAccount(account); setAddress(address); setCategory(category); setAmount(amount); setVOut(vOut); setFee(fee); } public void setAmount(BigDecimal amount) {
this.amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
daemon/src/main/java/com/neemre/btcdcli4j/daemon/BtcdDaemon.java
// Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/AlertListener.java // public abstract class AlertListener { // // private static final Logger LOG = LoggerFactory.getLogger(AlertListener.class); // // @Getter // private Observer observer; // // // public AlertListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // String alert = (String)cause; // LOG.trace("-- update(..): forwarding incoming 'ALERT' notification to " // + "'alertReceived(..)'"); // alertReceived(alert); // } // }; // } // // public void alertReceived(String alert) {} // } // // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/BlockListener.java // public abstract class BlockListener { // // private static final Logger LOG = LoggerFactory.getLogger(BlockListener.class); // // @Getter // private Observer observer; // // // public BlockListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // Block block = (Block)cause; // LOG.trace("-- update(..): forwarding incoming 'BLOCK' notification to " // + "'blockDetected(..)'"); // blockDetected(block); // } // }; // } // // public void blockDetected(Block block) {} // } // // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/WalletListener.java // public abstract class WalletListener { // // private static final Logger LOG = LoggerFactory.getLogger(WalletListener.class); // // @Getter // private Observer observer; // // // public WalletListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // Transaction transaction = (Transaction)cause; // LOG.trace("-- update(..): forwarding incoming 'WALLET' notification to " // + "'walletChanged(..)'"); // walletChanged(transaction); // } // }; // } // // public void walletChanged(Transaction transaction) {} // }
import java.util.Properties; import com.neemre.btcdcli4j.daemon.event.AlertListener; import com.neemre.btcdcli4j.daemon.event.BlockListener; import com.neemre.btcdcli4j.daemon.event.WalletListener;
package com.neemre.btcdcli4j.daemon; public interface BtcdDaemon { void addAlertListener(AlertListener listener); int countAlertListeners(); void removeAlertListener(AlertListener listener); void removeAlertListeners();
// Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/AlertListener.java // public abstract class AlertListener { // // private static final Logger LOG = LoggerFactory.getLogger(AlertListener.class); // // @Getter // private Observer observer; // // // public AlertListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // String alert = (String)cause; // LOG.trace("-- update(..): forwarding incoming 'ALERT' notification to " // + "'alertReceived(..)'"); // alertReceived(alert); // } // }; // } // // public void alertReceived(String alert) {} // } // // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/BlockListener.java // public abstract class BlockListener { // // private static final Logger LOG = LoggerFactory.getLogger(BlockListener.class); // // @Getter // private Observer observer; // // // public BlockListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // Block block = (Block)cause; // LOG.trace("-- update(..): forwarding incoming 'BLOCK' notification to " // + "'blockDetected(..)'"); // blockDetected(block); // } // }; // } // // public void blockDetected(Block block) {} // } // // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/WalletListener.java // public abstract class WalletListener { // // private static final Logger LOG = LoggerFactory.getLogger(WalletListener.class); // // @Getter // private Observer observer; // // // public WalletListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // Transaction transaction = (Transaction)cause; // LOG.trace("-- update(..): forwarding incoming 'WALLET' notification to " // + "'walletChanged(..)'"); // walletChanged(transaction); // } // }; // } // // public void walletChanged(Transaction transaction) {} // } // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/BtcdDaemon.java import java.util.Properties; import com.neemre.btcdcli4j.daemon.event.AlertListener; import com.neemre.btcdcli4j.daemon.event.BlockListener; import com.neemre.btcdcli4j.daemon.event.WalletListener; package com.neemre.btcdcli4j.daemon; public interface BtcdDaemon { void addAlertListener(AlertListener listener); int countAlertListeners(); void removeAlertListener(AlertListener listener); void removeAlertListeners();
void addBlockListener(BlockListener listener);
priiduneemre/btcd-cli4j
daemon/src/main/java/com/neemre/btcdcli4j/daemon/BtcdDaemon.java
// Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/AlertListener.java // public abstract class AlertListener { // // private static final Logger LOG = LoggerFactory.getLogger(AlertListener.class); // // @Getter // private Observer observer; // // // public AlertListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // String alert = (String)cause; // LOG.trace("-- update(..): forwarding incoming 'ALERT' notification to " // + "'alertReceived(..)'"); // alertReceived(alert); // } // }; // } // // public void alertReceived(String alert) {} // } // // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/BlockListener.java // public abstract class BlockListener { // // private static final Logger LOG = LoggerFactory.getLogger(BlockListener.class); // // @Getter // private Observer observer; // // // public BlockListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // Block block = (Block)cause; // LOG.trace("-- update(..): forwarding incoming 'BLOCK' notification to " // + "'blockDetected(..)'"); // blockDetected(block); // } // }; // } // // public void blockDetected(Block block) {} // } // // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/WalletListener.java // public abstract class WalletListener { // // private static final Logger LOG = LoggerFactory.getLogger(WalletListener.class); // // @Getter // private Observer observer; // // // public WalletListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // Transaction transaction = (Transaction)cause; // LOG.trace("-- update(..): forwarding incoming 'WALLET' notification to " // + "'walletChanged(..)'"); // walletChanged(transaction); // } // }; // } // // public void walletChanged(Transaction transaction) {} // }
import java.util.Properties; import com.neemre.btcdcli4j.daemon.event.AlertListener; import com.neemre.btcdcli4j.daemon.event.BlockListener; import com.neemre.btcdcli4j.daemon.event.WalletListener;
package com.neemre.btcdcli4j.daemon; public interface BtcdDaemon { void addAlertListener(AlertListener listener); int countAlertListeners(); void removeAlertListener(AlertListener listener); void removeAlertListeners(); void addBlockListener(BlockListener listener); int countBlockListeners(); void removeBlockListener(BlockListener listener); void removeBlockListeners();
// Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/AlertListener.java // public abstract class AlertListener { // // private static final Logger LOG = LoggerFactory.getLogger(AlertListener.class); // // @Getter // private Observer observer; // // // public AlertListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // String alert = (String)cause; // LOG.trace("-- update(..): forwarding incoming 'ALERT' notification to " // + "'alertReceived(..)'"); // alertReceived(alert); // } // }; // } // // public void alertReceived(String alert) {} // } // // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/BlockListener.java // public abstract class BlockListener { // // private static final Logger LOG = LoggerFactory.getLogger(BlockListener.class); // // @Getter // private Observer observer; // // // public BlockListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // Block block = (Block)cause; // LOG.trace("-- update(..): forwarding incoming 'BLOCK' notification to " // + "'blockDetected(..)'"); // blockDetected(block); // } // }; // } // // public void blockDetected(Block block) {} // } // // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/WalletListener.java // public abstract class WalletListener { // // private static final Logger LOG = LoggerFactory.getLogger(WalletListener.class); // // @Getter // private Observer observer; // // // public WalletListener() { // observer = new Observer() { // @Override // public void update(Observable monitor, Object cause) { // Transaction transaction = (Transaction)cause; // LOG.trace("-- update(..): forwarding incoming 'WALLET' notification to " // + "'walletChanged(..)'"); // walletChanged(transaction); // } // }; // } // // public void walletChanged(Transaction transaction) {} // } // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/BtcdDaemon.java import java.util.Properties; import com.neemre.btcdcli4j.daemon.event.AlertListener; import com.neemre.btcdcli4j.daemon.event.BlockListener; import com.neemre.btcdcli4j.daemon.event.WalletListener; package com.neemre.btcdcli4j.daemon; public interface BtcdDaemon { void addAlertListener(AlertListener listener); int countAlertListeners(); void removeAlertListener(AlertListener listener); void removeAlertListeners(); void addBlockListener(BlockListener listener); int countBlockListeners(); void removeBlockListener(BlockListener listener); void removeBlockListeners();
void addWalletListener(WalletListener listener);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/util/NumberUtils.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import java.util.Iterator; import java.util.Map; import lombok.AccessLevel; import lombok.NoArgsConstructor; import com.neemre.btcdcli4j.core.common.Defaults;
package com.neemre.btcdcli4j.core.util; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class NumberUtils { public static boolean isEven(int integer) { if (integer % 2 == 0) { return true; } else { return false; } } public static <T> Map<T, BigDecimal> setValueScale(Map<T, BigDecimal> pairs, int newScale) { Iterator<Map.Entry<T, BigDecimal>> iterator = pairs.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<T, BigDecimal> pair = iterator.next();
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/util/NumberUtils.java import java.math.BigDecimal; import java.util.Iterator; import java.util.Map; import lombok.AccessLevel; import lombok.NoArgsConstructor; import com.neemre.btcdcli4j.core.common.Defaults; package com.neemre.btcdcli4j.core.util; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class NumberUtils { public static boolean isEven(int integer) { if (integer % 2 == 0) { return true; } else { return false; } } public static <T> Map<T, BigDecimal> setValueScale(Map<T, BigDecimal> pairs, int newScale) { Iterator<Map.Entry<T, BigDecimal>> iterator = pairs.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<T, BigDecimal> pair = iterator.next();
pair.setValue(pair.getValue().setScale(newScale, Defaults.ROUNDING_MODE));
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/MemPoolTransaction.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import java.util.List; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults;
public class MemPoolTransaction extends Entity { private String txId; private Integer size; @Setter(AccessLevel.NONE) private BigDecimal fee; private Long time; private Integer height; @Setter(AccessLevel.NONE) @JsonProperty("startingpriority") private BigDecimal startingPriority; @Setter(AccessLevel.NONE) @JsonProperty("currentpriority") private BigDecimal currentPriority; private List<String> depends; public MemPoolTransaction(String txId, Integer size, BigDecimal fee, Long time, Integer height, BigDecimal startingPriority, BigDecimal currentPriority, List<String> depends) { setTxId(txId); setSize(size); setFee(fee); setTime(time); setHeight(height); setStartingPriority(startingPriority); setCurrentPriority(currentPriority); setDepends(depends); } public void setFee(BigDecimal fee) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/MemPoolTransaction.java import java.math.BigDecimal; import java.util.List; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults; public class MemPoolTransaction extends Entity { private String txId; private Integer size; @Setter(AccessLevel.NONE) private BigDecimal fee; private Long time; private Integer height; @Setter(AccessLevel.NONE) @JsonProperty("startingpriority") private BigDecimal startingPriority; @Setter(AccessLevel.NONE) @JsonProperty("currentpriority") private BigDecimal currentPriority; private List<String> depends; public MemPoolTransaction(String txId, Integer size, BigDecimal fee, Long time, Integer height, BigDecimal startingPriority, BigDecimal currentPriority, List<String> depends) { setTxId(txId); setSize(size); setFee(fee); setTime(time); setHeight(height); setStartingPriority(startingPriority); setCurrentPriority(currentPriority); setDepends(depends); } public void setFee(BigDecimal fee) {
this.fee = fee.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/Tip.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ChainStatuses.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ChainStatuses { // // ACTIVE("active"), // INVALID("invalid"), // HEADERS_ONLY("headers-only"), // VALID_HEADERS("valid-headers"), // VALID_FORK("valid-fork"), // UNKNOWN("unknown"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ChainStatuses forName(String name) { // if (name != null) { // for (ChainStatuses chainStatus : ChainStatuses.values()) { // if (name.equals(chainStatus.getName())) { // return chainStatus; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CHAINSTATUS_UNSUPPORTED.getDescription()); // } // }
import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.domain.enums.ChainStatuses;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class Tip extends Entity { private Integer height; private String hash; @JsonProperty("branchlen") private Integer branchLen;
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ChainStatuses.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ChainStatuses { // // ACTIVE("active"), // INVALID("invalid"), // HEADERS_ONLY("headers-only"), // VALID_HEADERS("valid-headers"), // VALID_FORK("valid-fork"), // UNKNOWN("unknown"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ChainStatuses forName(String name) { // if (name != null) { // for (ChainStatuses chainStatus : ChainStatuses.values()) { // if (name.equals(chainStatus.getName())) { // return chainStatus; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CHAINSTATUS_UNSUPPORTED.getDescription()); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Tip.java import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.domain.enums.ChainStatuses; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @AllArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class Tip extends Entity { private Integer height; private String hash; @JsonProperty("branchlen") private Integer branchLen;
private ChainStatuses status;
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/Account.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.AccessLevel; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class Account extends Entity { @JsonProperty("involvesWatchonly") private Boolean involvesWatchOnly; private String account; @Setter(AccessLevel.NONE) private BigDecimal amount; private Integer confirmations; public Account(Boolean involvesWatchOnly, String account, BigDecimal amount, Integer confirmations) { setInvolvesWatchOnly(involvesWatchOnly); setAccount(account); setAmount(amount); setConfirmations(confirmations); } public void setAmount(BigDecimal amount) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Account.java import java.math.BigDecimal; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.AccessLevel; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.neemre.btcdcli4j.core.common.Defaults; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class Account extends Entity { @JsonProperty("involvesWatchonly") private Boolean involvesWatchOnly; private String account; @Setter(AccessLevel.NONE) private BigDecimal amount; private Integer confirmations; public Account(Boolean involvesWatchOnly, String account, BigDecimal amount, Integer confirmations) { setInvolvesWatchOnly(involvesWatchOnly); setAccount(account); setAmount(amount); setConfirmations(confirmations); } public void setAmount(BigDecimal amount) {
this.amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/common/AgentConfigurator.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/NodeProperties.java // @Getter // @ToString // @AllArgsConstructor // public enum NodeProperties { // // RPC_PROTOCOL("node.bitcoind.rpc.protocol", "http"), // RPC_HOST("node.bitcoind.rpc.host", "127.0.0.1"), // RPC_PORT("node.bitcoind.rpc.port", "8332"), // RPC_USER("node.bitcoind.rpc.user", "user"), // RPC_PASSWORD("node.bitcoind.rpc.password", "password"), // HTTP_AUTH_SCHEME("node.bitcoind.http.auth_scheme", "Basic"), // ALERT_PORT("node.bitcoind.notification.alert.port", "5158"), // BLOCK_PORT("node.bitcoind.notification.block.port", "5159"), // WALLET_PORT("node.bitcoind.notification.wallet.port", "5160"); // // private final String key; // private final String defaultValue; // }
import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.Set; import lombok.Getter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.neemre.btcdcli4j.core.NodeProperties;
package com.neemre.btcdcli4j.core.common; /**An abstract superclass containing the core functionality required for constructing * &amp; configuring new <i>bitcoind</i> consumer instances (<i>i.e.</i> {@code BtcdClient} * (JSON-RPC API), {@code BtcdDaemon} ('callback-via-shell-command' API) etc.).*/ public abstract class AgentConfigurator { private static final Logger LOG = LoggerFactory.getLogger(AgentConfigurator.class); @Getter private Properties nodeConfig;
// Path: core/src/main/java/com/neemre/btcdcli4j/core/NodeProperties.java // @Getter // @ToString // @AllArgsConstructor // public enum NodeProperties { // // RPC_PROTOCOL("node.bitcoind.rpc.protocol", "http"), // RPC_HOST("node.bitcoind.rpc.host", "127.0.0.1"), // RPC_PORT("node.bitcoind.rpc.port", "8332"), // RPC_USER("node.bitcoind.rpc.user", "user"), // RPC_PASSWORD("node.bitcoind.rpc.password", "password"), // HTTP_AUTH_SCHEME("node.bitcoind.http.auth_scheme", "Basic"), // ALERT_PORT("node.bitcoind.notification.alert.port", "5158"), // BLOCK_PORT("node.bitcoind.notification.block.port", "5159"), // WALLET_PORT("node.bitcoind.notification.wallet.port", "5160"); // // private final String key; // private final String defaultValue; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/common/AgentConfigurator.java import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.Set; import lombok.Getter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.neemre.btcdcli4j.core.NodeProperties; package com.neemre.btcdcli4j.core.common; /**An abstract superclass containing the core functionality required for constructing * &amp; configuring new <i>bitcoind</i> consumer instances (<i>i.e.</i> {@code BtcdClient} * (JSON-RPC API), {@code BtcdDaemon} ('callback-via-shell-command' API) etc.).*/ public abstract class AgentConfigurator { private static final Logger LOG = LoggerFactory.getLogger(AgentConfigurator.class); @Getter private Properties nodeConfig;
public abstract Set<NodeProperties> getRequiredProperties();
priiduneemre/btcd-cli4j
daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/WalletListener.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Transaction.java // @Data // @NoArgsConstructor // @ToString(callSuper = true) // @EqualsAndHashCode(callSuper = false) // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class Transaction extends Entity { // // @Setter(AccessLevel.NONE) // private BigDecimal amount; // @Setter(AccessLevel.NONE) // private BigDecimal fee; // private Integer confirmations; // private Boolean generated; // @JsonProperty("blockhash") // private String blockHash; // @JsonProperty("blockindex") // private Integer blockIndex; // @JsonProperty("blocktime") // private Long blockTime; // @JsonProperty("txid") // private String txId; // @JsonProperty("walletconflicts") // private List<String> walletConflicts; // private Long time; // @JsonProperty("timereceived") // private Long timeReceived; // private String comment; // private String to; // private List<PaymentOverview> details; // private String hex; // // // public Transaction(BigDecimal amount, BigDecimal fee, Integer confirmations, Boolean generated, // String blockHash, Integer blockIndex, Long blockTime, String txId, // List<String> walletConflicts, Long time, Long timeReceived, String comment, String to, // List<PaymentOverview> details, String hex) { // setAmount(amount); // setFee(fee); // setConfirmations(confirmations); // setGenerated(generated); // setBlockHash(blockHash); // setBlockIndex(blockIndex); // setBlockTime(blockTime); // setTxId(txId); // setWalletConflicts(walletConflicts); // setTime(time); // setTimeReceived(timeReceived); // setComment(comment); // setTo(to); // setDetails(details); // setHex(hex); // } // // public void setAmount(BigDecimal amount) { // this.amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); // } // // public void setFee(BigDecimal fee) { // this.fee = fee.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); // } // }
import java.util.Observable; import java.util.Observer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import lombok.Getter; import com.neemre.btcdcli4j.core.domain.Transaction;
package com.neemre.btcdcli4j.daemon.event; /**An abstract adapter class for receiving {@code WALLET} notifications. Extend this class to * override any methods of interest.*/ public abstract class WalletListener { private static final Logger LOG = LoggerFactory.getLogger(WalletListener.class); @Getter private Observer observer; public WalletListener() { observer = new Observer() { @Override public void update(Observable monitor, Object cause) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/Transaction.java // @Data // @NoArgsConstructor // @ToString(callSuper = true) // @EqualsAndHashCode(callSuper = false) // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class Transaction extends Entity { // // @Setter(AccessLevel.NONE) // private BigDecimal amount; // @Setter(AccessLevel.NONE) // private BigDecimal fee; // private Integer confirmations; // private Boolean generated; // @JsonProperty("blockhash") // private String blockHash; // @JsonProperty("blockindex") // private Integer blockIndex; // @JsonProperty("blocktime") // private Long blockTime; // @JsonProperty("txid") // private String txId; // @JsonProperty("walletconflicts") // private List<String> walletConflicts; // private Long time; // @JsonProperty("timereceived") // private Long timeReceived; // private String comment; // private String to; // private List<PaymentOverview> details; // private String hex; // // // public Transaction(BigDecimal amount, BigDecimal fee, Integer confirmations, Boolean generated, // String blockHash, Integer blockIndex, Long blockTime, String txId, // List<String> walletConflicts, Long time, Long timeReceived, String comment, String to, // List<PaymentOverview> details, String hex) { // setAmount(amount); // setFee(fee); // setConfirmations(confirmations); // setGenerated(generated); // setBlockHash(blockHash); // setBlockIndex(blockIndex); // setBlockTime(blockTime); // setTxId(txId); // setWalletConflicts(walletConflicts); // setTime(time); // setTimeReceived(timeReceived); // setComment(comment); // setTo(to); // setDetails(details); // setHex(hex); // } // // public void setAmount(BigDecimal amount) { // this.amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); // } // // public void setFee(BigDecimal fee) { // this.fee = fee.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); // } // } // Path: daemon/src/main/java/com/neemre/btcdcli4j/daemon/event/WalletListener.java import java.util.Observable; import java.util.Observer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import lombok.Getter; import com.neemre.btcdcli4j.core.domain.Transaction; package com.neemre.btcdcli4j.daemon.event; /**An abstract adapter class for receiving {@code WALLET} notifications. Extend this class to * override any methods of interest.*/ public abstract class WalletListener { private static final Logger LOG = LoggerFactory.getLogger(WalletListener.class); @Getter private Observer observer; public WalletListener() { observer = new Observer() { @Override public void update(Observable monitor, Object cause) {
Transaction transaction = (Transaction)cause;
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/BlockChainInfo.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ChainTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ChainTypes { // // MAINNET("main"), // TESTNET("test"), // REGTEST("regtest"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ChainTypes forName(String name) { // if (name != null) { // for (ChainTypes chainType : ChainTypes.values()) { // if (name.equals(chainType.getName())) { // return chainType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CHAINTYPE_UNSUPPORTED.getDescription()); // } // }
import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.ChainTypes;
package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class BlockChainInfo extends Entity {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ChainTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ChainTypes { // // MAINNET("main"), // TESTNET("test"), // REGTEST("regtest"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ChainTypes forName(String name) { // if (name != null) { // for (ChainTypes chainType : ChainTypes.values()) { // if (name.equals(chainType.getName())) { // return chainType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CHAINTYPE_UNSUPPORTED.getDescription()); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/BlockChainInfo.java import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.ChainTypes; package com.neemre.btcdcli4j.core.domain; @Data @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = false) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class BlockChainInfo extends Entity {
private ChainTypes chain;
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/domain/BlockChainInfo.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ChainTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ChainTypes { // // MAINNET("main"), // TESTNET("test"), // REGTEST("regtest"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ChainTypes forName(String name) { // if (name != null) { // for (ChainTypes chainType : ChainTypes.values()) { // if (name.equals(chainType.getName())) { // return chainType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CHAINTYPE_UNSUPPORTED.getDescription()); // } // }
import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.ChainTypes;
@JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class BlockChainInfo extends Entity { private ChainTypes chain; private Integer blocks; private Integer headers; @JsonProperty("bestblockhash") private String bestBlockHash; @Setter(AccessLevel.NONE) private BigDecimal difficulty; @Setter(AccessLevel.NONE) @JsonProperty("verificationprogress") private BigDecimal verificationProgress; @JsonProperty("chainwork") private String chainWork; public BlockChainInfo(ChainTypes chain, Integer blocks, Integer headers, String bestBlockHash, BigDecimal difficulty, BigDecimal verificationProgress, String chainWork) { setChain(chain); setBlocks(blocks); setHeaders(headers); setBestBlockHash(bestBlockHash); setDifficulty(difficulty); setVerificationProgress(verificationProgress); setChainWork(chainWork); } public void setDifficulty(BigDecimal difficulty) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/enums/ChainTypes.java // @ToString // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public enum ChainTypes { // // MAINNET("main"), // TESTNET("test"), // REGTEST("regtest"); // // private final String name; // // // @JsonValue // public String getName() { // return name; // } // // @JsonCreator // public static ChainTypes forName(String name) { // if (name != null) { // for (ChainTypes chainType : ChainTypes.values()) { // if (name.equals(chainType.getName())) { // return chainType; // } // } // } // throw new IllegalArgumentException(Errors.ARGS_BTCD_CHAINTYPE_UNSUPPORTED.getDescription()); // } // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/domain/BlockChainInfo.java import java.math.BigDecimal; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.neemre.btcdcli4j.core.common.Defaults; import com.neemre.btcdcli4j.core.domain.enums.ChainTypes; @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class BlockChainInfo extends Entity { private ChainTypes chain; private Integer blocks; private Integer headers; @JsonProperty("bestblockhash") private String bestBlockHash; @Setter(AccessLevel.NONE) private BigDecimal difficulty; @Setter(AccessLevel.NONE) @JsonProperty("verificationprogress") private BigDecimal verificationProgress; @JsonProperty("chainwork") private String chainWork; public BlockChainInfo(ChainTypes chain, Integer blocks, Integer headers, String bestBlockHash, BigDecimal difficulty, BigDecimal verificationProgress, String chainWork) { setChain(chain); setBlocks(blocks); setHeaders(headers); setBestBlockHash(bestBlockHash); setDifficulty(difficulty); setVerificationProgress(verificationProgress); setChainWork(chainWork); } public void setDifficulty(BigDecimal difficulty) {
this.difficulty = difficulty.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE);
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/JsonPrimitiveParser.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Constants.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Constants { // // public static final Charset US_ASCII = Charset.forName("US-ASCII"); // public static final Charset UTF_8 = Charset.forName("UTF-8"); // // public static final String STRING_EMPTY = ""; // public static final String STRING_NULL = "null"; // public static final String STRING_SPACE = " "; // public static final String STRING_SINGLE_QUOTE = "'"; // public static final String STRING_DOUBLE_QUOTE = "\""; // // public static final char CHAR_NULL = '\u0000'; // // public static final String UNIX_NEWLINE = "\n"; // public static final String WINDOWS_NEWLINE ="\r\n"; // // public static final String BINARY_DIGITS = "01"; // public static final String DECIMAL_DIGITS = "0123456789"; // public static final String HEXADECIMAL_DIGITS = "0123456789ABCDEF"; // public static final String BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; // public static final String BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw" // + "xyz0123456789+/"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import java.math.BigInteger; import org.apache.commons.lang3.StringEscapeUtils; import com.neemre.btcdcli4j.core.common.Constants; import com.neemre.btcdcli4j.core.common.Defaults;
package com.neemre.btcdcli4j.core.jsonrpc; public class JsonPrimitiveParser { public Integer parseInteger(String integerJson) { try { return Integer.valueOf(integerJson); } catch (NumberFormatException e) { return null; } } public Long parseLong(String longJson) { try { return Long.valueOf(longJson); } catch (NumberFormatException e) { return null; } } public BigInteger parseBigInteger(String bigIntegerJson) { try { return new BigInteger(bigIntegerJson); } catch (NumberFormatException e) { return null; } } public BigDecimal parseBigDecimal(String bigDecimalJson) { try {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Constants.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Constants { // // public static final Charset US_ASCII = Charset.forName("US-ASCII"); // public static final Charset UTF_8 = Charset.forName("UTF-8"); // // public static final String STRING_EMPTY = ""; // public static final String STRING_NULL = "null"; // public static final String STRING_SPACE = " "; // public static final String STRING_SINGLE_QUOTE = "'"; // public static final String STRING_DOUBLE_QUOTE = "\""; // // public static final char CHAR_NULL = '\u0000'; // // public static final String UNIX_NEWLINE = "\n"; // public static final String WINDOWS_NEWLINE ="\r\n"; // // public static final String BINARY_DIGITS = "01"; // public static final String DECIMAL_DIGITS = "0123456789"; // public static final String HEXADECIMAL_DIGITS = "0123456789ABCDEF"; // public static final String BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; // public static final String BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw" // + "xyz0123456789+/"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/JsonPrimitiveParser.java import java.math.BigDecimal; import java.math.BigInteger; import org.apache.commons.lang3.StringEscapeUtils; import com.neemre.btcdcli4j.core.common.Constants; import com.neemre.btcdcli4j.core.common.Defaults; package com.neemre.btcdcli4j.core.jsonrpc; public class JsonPrimitiveParser { public Integer parseInteger(String integerJson) { try { return Integer.valueOf(integerJson); } catch (NumberFormatException e) { return null; } } public Long parseLong(String longJson) { try { return Long.valueOf(longJson); } catch (NumberFormatException e) { return null; } } public BigInteger parseBigInteger(String bigIntegerJson) { try { return new BigInteger(bigIntegerJson); } catch (NumberFormatException e) { return null; } } public BigDecimal parseBigDecimal(String bigDecimalJson) { try {
return new BigDecimal(bigDecimalJson).setScale(Defaults.DECIMAL_SCALE,
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/JsonPrimitiveParser.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Constants.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Constants { // // public static final Charset US_ASCII = Charset.forName("US-ASCII"); // public static final Charset UTF_8 = Charset.forName("UTF-8"); // // public static final String STRING_EMPTY = ""; // public static final String STRING_NULL = "null"; // public static final String STRING_SPACE = " "; // public static final String STRING_SINGLE_QUOTE = "'"; // public static final String STRING_DOUBLE_QUOTE = "\""; // // public static final char CHAR_NULL = '\u0000'; // // public static final String UNIX_NEWLINE = "\n"; // public static final String WINDOWS_NEWLINE ="\r\n"; // // public static final String BINARY_DIGITS = "01"; // public static final String DECIMAL_DIGITS = "0123456789"; // public static final String HEXADECIMAL_DIGITS = "0123456789ABCDEF"; // public static final String BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; // public static final String BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw" // + "xyz0123456789+/"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // }
import java.math.BigDecimal; import java.math.BigInteger; import org.apache.commons.lang3.StringEscapeUtils; import com.neemre.btcdcli4j.core.common.Constants; import com.neemre.btcdcli4j.core.common.Defaults;
return null; } } public Long parseLong(String longJson) { try { return Long.valueOf(longJson); } catch (NumberFormatException e) { return null; } } public BigInteger parseBigInteger(String bigIntegerJson) { try { return new BigInteger(bigIntegerJson); } catch (NumberFormatException e) { return null; } } public BigDecimal parseBigDecimal(String bigDecimalJson) { try { return new BigDecimal(bigDecimalJson).setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); } catch (NumberFormatException e) { return null; } } public Boolean parseBoolean(String booleanJson) {
// Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Constants.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Constants { // // public static final Charset US_ASCII = Charset.forName("US-ASCII"); // public static final Charset UTF_8 = Charset.forName("UTF-8"); // // public static final String STRING_EMPTY = ""; // public static final String STRING_NULL = "null"; // public static final String STRING_SPACE = " "; // public static final String STRING_SINGLE_QUOTE = "'"; // public static final String STRING_DOUBLE_QUOTE = "\""; // // public static final char CHAR_NULL = '\u0000'; // // public static final String UNIX_NEWLINE = "\n"; // public static final String WINDOWS_NEWLINE ="\r\n"; // // public static final String BINARY_DIGITS = "01"; // public static final String DECIMAL_DIGITS = "0123456789"; // public static final String HEXADECIMAL_DIGITS = "0123456789ABCDEF"; // public static final String BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; // public static final String BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw" // + "xyz0123456789+/"; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/common/Defaults.java // @NoArgsConstructor(access = AccessLevel.PRIVATE) // public final class Defaults { // // public static final int DECIMAL_SCALE = 8; // public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; // // public static final String[] NODE_VERSIONS = {"0.10.0", "0.10.1", "0.10.2", "0.10.3"}; // public static final String JSON_RPC_VERSION = "1.0"; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/JsonPrimitiveParser.java import java.math.BigDecimal; import java.math.BigInteger; import org.apache.commons.lang3.StringEscapeUtils; import com.neemre.btcdcli4j.core.common.Constants; import com.neemre.btcdcli4j.core.common.Defaults; return null; } } public Long parseLong(String longJson) { try { return Long.valueOf(longJson); } catch (NumberFormatException e) { return null; } } public BigInteger parseBigInteger(String bigIntegerJson) { try { return new BigInteger(bigIntegerJson); } catch (NumberFormatException e) { return null; } } public BigDecimal parseBigDecimal(String bigDecimalJson) { try { return new BigDecimal(bigDecimalJson).setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); } catch (NumberFormatException e) { return null; } } public Boolean parseBoolean(String booleanJson) {
if (!booleanJson.equals(Constants.STRING_NULL)) {
priiduneemre/btcd-cli4j
core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/deserialization/JsonRpcResponseDeserializer.java
// Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/domain/JsonRpcError.java // @Data // @NoArgsConstructor // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class JsonRpcError { // // private Integer code; // private String message; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/domain/JsonRpcResponse.java // @Data // @NoArgsConstructor // @AllArgsConstructor // @ToString(callSuper = true) // @EqualsAndHashCode(callSuper = false) // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonDeserialize(using = JsonRpcResponseDeserializer.class) // public class JsonRpcResponse extends JsonRpcMessage { // // private String result; // private JsonRpcError error; // }
import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import com.neemre.btcdcli4j.core.jsonrpc.domain.JsonRpcError; import com.neemre.btcdcli4j.core.jsonrpc.domain.JsonRpcResponse;
package com.neemre.btcdcli4j.core.jsonrpc.deserialization; public class JsonRpcResponseDeserializer extends JsonDeserializer<JsonRpcResponse> { @Override public JsonRpcResponse deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { RawJsonRpcResponse rawRpcResponse = parser.readValueAs(RawJsonRpcResponse.class); return rawRpcResponse.toJsonRpcResponse(); } private static class RawJsonRpcResponse { public JsonNode result;
// Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/domain/JsonRpcError.java // @Data // @NoArgsConstructor // @AllArgsConstructor // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class JsonRpcError { // // private Integer code; // private String message; // } // // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/domain/JsonRpcResponse.java // @Data // @NoArgsConstructor // @AllArgsConstructor // @ToString(callSuper = true) // @EqualsAndHashCode(callSuper = false) // @JsonInclude(Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonDeserialize(using = JsonRpcResponseDeserializer.class) // public class JsonRpcResponse extends JsonRpcMessage { // // private String result; // private JsonRpcError error; // } // Path: core/src/main/java/com/neemre/btcdcli4j/core/jsonrpc/deserialization/JsonRpcResponseDeserializer.java import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import com.neemre.btcdcli4j.core.jsonrpc.domain.JsonRpcError; import com.neemre.btcdcli4j.core.jsonrpc.domain.JsonRpcResponse; package com.neemre.btcdcli4j.core.jsonrpc.deserialization; public class JsonRpcResponseDeserializer extends JsonDeserializer<JsonRpcResponse> { @Override public JsonRpcResponse deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { RawJsonRpcResponse rawRpcResponse = parser.readValueAs(RawJsonRpcResponse.class); return rawRpcResponse.toJsonRpcResponse(); } private static class RawJsonRpcResponse { public JsonNode result;
public JsonRpcError error;
rongzhu8888/magic-dao
src/main/java/pers/zr/opensource/magic/dao/action/Action.java
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/ActionMode.java // public enum ActionMode { // // INSERT, UPDATE, DELETE, QUERY // } // // Path: src/main/java/pers/zr/opensource/magic/dao/shard/TableShardHandler.java // public interface TableShardHandler { // // public String getRealTableName(TableShardStrategy shardStrategy, Object... columnValues); // // // } // // Path: src/main/java/pers/zr/opensource/magic/dao/shard/TableShardStrategy.java // public class TableShardStrategy { // // private String shardTable; // // private int shardCount; // // private String[] shardColumns; // // private String separator; // // public TableShardStrategy(String shardTable, int shardCount, String[] shardColumns, String separator) { // this.shardTable = shardTable; // this.shardCount = shardCount; // this.shardColumns = shardColumns; // this.separator = separator; // } // // public String getShardTable() { // return shardTable; // } // // public int getShardCount() { // return shardCount; // } // // public String[] getShardColumns() { // return shardColumns; // } // // public String getSeparator() { // return separator; // } // }
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import pers.zr.opensource.magic.dao.constants.ActionMode; import pers.zr.opensource.magic.dao.shard.TableShardHandler; import pers.zr.opensource.magic.dao.shard.TableShardStrategy;
package pers.zr.opensource.magic.dao.action; /** * Created by zhurong on 2016-4-28. */ public abstract class Action { protected Log log = LogFactory.getLog(getClass()); protected ActionTable table; protected String sql; protected Object[] params; public abstract String getSql(); public abstract Object[] getParams();
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/ActionMode.java // public enum ActionMode { // // INSERT, UPDATE, DELETE, QUERY // } // // Path: src/main/java/pers/zr/opensource/magic/dao/shard/TableShardHandler.java // public interface TableShardHandler { // // public String getRealTableName(TableShardStrategy shardStrategy, Object... columnValues); // // // } // // Path: src/main/java/pers/zr/opensource/magic/dao/shard/TableShardStrategy.java // public class TableShardStrategy { // // private String shardTable; // // private int shardCount; // // private String[] shardColumns; // // private String separator; // // public TableShardStrategy(String shardTable, int shardCount, String[] shardColumns, String separator) { // this.shardTable = shardTable; // this.shardCount = shardCount; // this.shardColumns = shardColumns; // this.separator = separator; // } // // public String getShardTable() { // return shardTable; // } // // public int getShardCount() { // return shardCount; // } // // public String[] getShardColumns() { // return shardColumns; // } // // public String getSeparator() { // return separator; // } // } // Path: src/main/java/pers/zr/opensource/magic/dao/action/Action.java import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import pers.zr.opensource.magic.dao.constants.ActionMode; import pers.zr.opensource.magic.dao.shard.TableShardHandler; import pers.zr.opensource.magic.dao.shard.TableShardStrategy; package pers.zr.opensource.magic.dao.action; /** * Created by zhurong on 2016-4-28. */ public abstract class Action { protected Log log = LogFactory.getLog(getClass()); protected ActionTable table; protected String sql; protected Object[] params; public abstract String getSql(); public abstract Object[] getParams();
public abstract ActionMode getActionMode();
rongzhu8888/magic-dao
src/main/java/pers/zr/opensource/magic/dao/matcher/LikeMatcher.java
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/MatchType.java // public enum MatchType { // // EQUALS("="), // // GREATER(">"), // // LESS("<"), // // NOT_EQUALS("!="), // // GREATER_OR_EQUALS(">="), // // LESS_OR_EQUALS("<="), // // IN("IN"), // // LIKE("LIKE"), // // BETWEEN_AND("BETWEEN ? AND"); // // // public String value; // // MatchType(String value) { // this.value = value; // } // // }
import pers.zr.opensource.magic.dao.constants.MatchType;
package pers.zr.opensource.magic.dao.matcher; /** * Created by zhurong on 2016-4-29. */ public class LikeMatcher extends Matcher { private String value; public LikeMatcher(String column, String value) { this.column = column;
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/MatchType.java // public enum MatchType { // // EQUALS("="), // // GREATER(">"), // // LESS("<"), // // NOT_EQUALS("!="), // // GREATER_OR_EQUALS(">="), // // LESS_OR_EQUALS("<="), // // IN("IN"), // // LIKE("LIKE"), // // BETWEEN_AND("BETWEEN ? AND"); // // // public String value; // // MatchType(String value) { // this.value = value; // } // // } // Path: src/main/java/pers/zr/opensource/magic/dao/matcher/LikeMatcher.java import pers.zr.opensource.magic.dao.constants.MatchType; package pers.zr.opensource.magic.dao.matcher; /** * Created by zhurong on 2016-4-29. */ public class LikeMatcher extends Matcher { private String value; public LikeMatcher(String column, String value) { this.column = column;
this.value = "%" + convertSpecialChar(value, MatchType.LIKE) + "%";
rongzhu8888/magic-dao
src/main/java/pers/zr/opensource/magic/dao/order/Order.java
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/OrderType.java // public enum OrderType { // // ASC, DESC // }
import pers.zr.opensource.magic.dao.constants.OrderType;
package pers.zr.opensource.magic.dao.order; /** * Created by zhurong on 2016-5-10. */ public class Order { private String column;
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/OrderType.java // public enum OrderType { // // ASC, DESC // } // Path: src/main/java/pers/zr/opensource/magic/dao/order/Order.java import pers.zr.opensource.magic.dao.constants.OrderType; package pers.zr.opensource.magic.dao.order; /** * Created by zhurong on 2016-5-10. */ public class Order { private String column;
private OrderType type;
rongzhu8888/magic-dao
src/main/java/pers/zr/opensource/magic/dao/mapper/GenericMapper.java
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/MethodType.java // public enum MethodType { // // GET, SET // }
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.jdbc.core.RowMapper; import pers.zr.opensource.magic.dao.constants.MethodType; import java.io.Serializable; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.*;
package pers.zr.opensource.magic.dao.mapper; /** * Created by zhurong on 2016-5-6. */ public class GenericMapper<ENTITY extends Serializable> implements RowMapper<ENTITY> { private static Log log = LogFactory.getLog(GenericMapper.class); private Class<ENTITY> entityClass; public GenericMapper(Class<ENTITY> entityClass) { this.entityClass = entityClass; } @Override public ENTITY mapRow(ResultSet rs, int i) throws SQLException { ENTITY entity; try { entity = this.entityClass.newInstance(); ResultSetMetaData meta = rs.getMetaData(); for(int k=1; k<=meta.getColumnCount(); k++) { String column = meta.getColumnName(k); Field field = MapperContextHolder.getFieldWithColumn(entityClass, column); if(field == null) { continue; }
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/MethodType.java // public enum MethodType { // // GET, SET // } // Path: src/main/java/pers/zr/opensource/magic/dao/mapper/GenericMapper.java import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.jdbc.core.RowMapper; import pers.zr.opensource.magic.dao.constants.MethodType; import java.io.Serializable; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.*; package pers.zr.opensource.magic.dao.mapper; /** * Created by zhurong on 2016-5-6. */ public class GenericMapper<ENTITY extends Serializable> implements RowMapper<ENTITY> { private static Log log = LogFactory.getLog(GenericMapper.class); private Class<ENTITY> entityClass; public GenericMapper(Class<ENTITY> entityClass) { this.entityClass = entityClass; } @Override public ENTITY mapRow(ResultSet rs, int i) throws SQLException { ENTITY entity; try { entity = this.entityClass.newInstance(); ResultSetMetaData meta = rs.getMetaData(); for(int k=1; k<=meta.getColumnCount(); k++) { String column = meta.getColumnName(k); Field field = MapperContextHolder.getFieldWithColumn(entityClass, column); if(field == null) { continue; }
Method setMethod = MapperContextHolder.getMethod(entityClass, field, MethodType.SET);
rongzhu8888/magic-dao
src/main/java/pers/zr/opensource/magic/dao/matcher/RightLikeMatcher.java
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/MatchType.java // public enum MatchType { // // EQUALS("="), // // GREATER(">"), // // LESS("<"), // // NOT_EQUALS("!="), // // GREATER_OR_EQUALS(">="), // // LESS_OR_EQUALS("<="), // // IN("IN"), // // LIKE("LIKE"), // // BETWEEN_AND("BETWEEN ? AND"); // // // public String value; // // MatchType(String value) { // this.value = value; // } // // }
import pers.zr.opensource.magic.dao.constants.MatchType;
package pers.zr.opensource.magic.dao.matcher; /** * Created by zhurong on 2016-5-5. */ public class RightLikeMatcher extends Matcher { private String value; public RightLikeMatcher(String column, String value) { this.column = column;
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/MatchType.java // public enum MatchType { // // EQUALS("="), // // GREATER(">"), // // LESS("<"), // // NOT_EQUALS("!="), // // GREATER_OR_EQUALS(">="), // // LESS_OR_EQUALS("<="), // // IN("IN"), // // LIKE("LIKE"), // // BETWEEN_AND("BETWEEN ? AND"); // // // public String value; // // MatchType(String value) { // this.value = value; // } // // } // Path: src/main/java/pers/zr/opensource/magic/dao/matcher/RightLikeMatcher.java import pers.zr.opensource.magic.dao.constants.MatchType; package pers.zr.opensource.magic.dao.matcher; /** * Created by zhurong on 2016-5-5. */ public class RightLikeMatcher extends Matcher { private String value; public RightLikeMatcher(String column, String value) { this.column = column;
this.value = "%" + convertSpecialChar(value, MatchType.LIKE);
rongzhu8888/magic-dao
src/main/java/pers/zr/opensource/magic/dao/action/Query.java
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/ActionMode.java // public enum ActionMode { // // INSERT, UPDATE, DELETE, QUERY // } // // Path: src/main/java/pers/zr/opensource/magic/dao/order/Order.java // public class Order { // // private String column; // // private OrderType type; // // public Order(String column, OrderType type) { // this.column = column; // this.type = type; // } // // public String getColumn() { // return column; // } // // public OrderType getType() { // return type; // } // } // // Path: src/main/java/pers/zr/opensource/magic/dao/page/Page.java // public class Page { // // private int pageNo; // // private int pageSize; // // public Page(int pageNo, int pageSize) { // this.pageNo = pageNo; // this.pageSize = pageSize; // } // // public int getPageNo() { // return pageNo; // } // // public void setPageNo(int pageNo) { // this.pageNo = pageNo; // } // // public int getPageSize() { // return pageSize; // } // // public void setPageSize(int pageSize) { // this.pageSize = pageSize; // } // }
import pers.zr.opensource.magic.dao.constants.ActionMode; import pers.zr.opensource.magic.dao.order.Order; import pers.zr.opensource.magic.dao.page.Page; import java.util.List;
package pers.zr.opensource.magic.dao.action; /** * Created by zhurong on 2016-4-28. */ public class Query extends ConditionalAction { private List<String> queryFields;
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/ActionMode.java // public enum ActionMode { // // INSERT, UPDATE, DELETE, QUERY // } // // Path: src/main/java/pers/zr/opensource/magic/dao/order/Order.java // public class Order { // // private String column; // // private OrderType type; // // public Order(String column, OrderType type) { // this.column = column; // this.type = type; // } // // public String getColumn() { // return column; // } // // public OrderType getType() { // return type; // } // } // // Path: src/main/java/pers/zr/opensource/magic/dao/page/Page.java // public class Page { // // private int pageNo; // // private int pageSize; // // public Page(int pageNo, int pageSize) { // this.pageNo = pageNo; // this.pageSize = pageSize; // } // // public int getPageNo() { // return pageNo; // } // // public void setPageNo(int pageNo) { // this.pageNo = pageNo; // } // // public int getPageSize() { // return pageSize; // } // // public void setPageSize(int pageSize) { // this.pageSize = pageSize; // } // } // Path: src/main/java/pers/zr/opensource/magic/dao/action/Query.java import pers.zr.opensource.magic.dao.constants.ActionMode; import pers.zr.opensource.magic.dao.order.Order; import pers.zr.opensource.magic.dao.page.Page; import java.util.List; package pers.zr.opensource.magic.dao.action; /** * Created by zhurong on 2016-4-28. */ public class Query extends ConditionalAction { private List<String> queryFields;
private Page page;
rongzhu8888/magic-dao
src/main/java/pers/zr/opensource/magic/dao/action/Query.java
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/ActionMode.java // public enum ActionMode { // // INSERT, UPDATE, DELETE, QUERY // } // // Path: src/main/java/pers/zr/opensource/magic/dao/order/Order.java // public class Order { // // private String column; // // private OrderType type; // // public Order(String column, OrderType type) { // this.column = column; // this.type = type; // } // // public String getColumn() { // return column; // } // // public OrderType getType() { // return type; // } // } // // Path: src/main/java/pers/zr/opensource/magic/dao/page/Page.java // public class Page { // // private int pageNo; // // private int pageSize; // // public Page(int pageNo, int pageSize) { // this.pageNo = pageNo; // this.pageSize = pageSize; // } // // public int getPageNo() { // return pageNo; // } // // public void setPageNo(int pageNo) { // this.pageNo = pageNo; // } // // public int getPageSize() { // return pageSize; // } // // public void setPageSize(int pageSize) { // this.pageSize = pageSize; // } // }
import pers.zr.opensource.magic.dao.constants.ActionMode; import pers.zr.opensource.magic.dao.order.Order; import pers.zr.opensource.magic.dao.page.Page; import java.util.List;
package pers.zr.opensource.magic.dao.action; /** * Created by zhurong on 2016-4-28. */ public class Query extends ConditionalAction { private List<String> queryFields; private Page page;
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/ActionMode.java // public enum ActionMode { // // INSERT, UPDATE, DELETE, QUERY // } // // Path: src/main/java/pers/zr/opensource/magic/dao/order/Order.java // public class Order { // // private String column; // // private OrderType type; // // public Order(String column, OrderType type) { // this.column = column; // this.type = type; // } // // public String getColumn() { // return column; // } // // public OrderType getType() { // return type; // } // } // // Path: src/main/java/pers/zr/opensource/magic/dao/page/Page.java // public class Page { // // private int pageNo; // // private int pageSize; // // public Page(int pageNo, int pageSize) { // this.pageNo = pageNo; // this.pageSize = pageSize; // } // // public int getPageNo() { // return pageNo; // } // // public void setPageNo(int pageNo) { // this.pageNo = pageNo; // } // // public int getPageSize() { // return pageSize; // } // // public void setPageSize(int pageSize) { // this.pageSize = pageSize; // } // } // Path: src/main/java/pers/zr/opensource/magic/dao/action/Query.java import pers.zr.opensource.magic.dao.constants.ActionMode; import pers.zr.opensource.magic.dao.order.Order; import pers.zr.opensource.magic.dao.page.Page; import java.util.List; package pers.zr.opensource.magic.dao.action; /** * Created by zhurong on 2016-4-28. */ public class Query extends ConditionalAction { private List<String> queryFields; private Page page;
private List<Order> orders;
rongzhu8888/magic-dao
src/main/java/pers/zr/opensource/magic/dao/action/Query.java
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/ActionMode.java // public enum ActionMode { // // INSERT, UPDATE, DELETE, QUERY // } // // Path: src/main/java/pers/zr/opensource/magic/dao/order/Order.java // public class Order { // // private String column; // // private OrderType type; // // public Order(String column, OrderType type) { // this.column = column; // this.type = type; // } // // public String getColumn() { // return column; // } // // public OrderType getType() { // return type; // } // } // // Path: src/main/java/pers/zr/opensource/magic/dao/page/Page.java // public class Page { // // private int pageNo; // // private int pageSize; // // public Page(int pageNo, int pageSize) { // this.pageNo = pageNo; // this.pageSize = pageSize; // } // // public int getPageNo() { // return pageNo; // } // // public void setPageNo(int pageNo) { // this.pageNo = pageNo; // } // // public int getPageSize() { // return pageSize; // } // // public void setPageSize(int pageSize) { // this.pageSize = pageSize; // } // }
import pers.zr.opensource.magic.dao.constants.ActionMode; import pers.zr.opensource.magic.dao.order.Order; import pers.zr.opensource.magic.dao.page.Page; import java.util.List;
} if (log.isDebugEnabled()) { log.debug("### [ " + sql + "] ###"); } return this.sql; } @Override public Object[] getParams() { List<Object> paramsList = getConParams(); //paging if(null != page) { int limit = page.getPageSize(); int offset = (page.getPageNo() - 1) * limit; paramsList.add(limit); paramsList.add(offset); } this.params = paramsList.toArray(); return this.params; } @Override
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/ActionMode.java // public enum ActionMode { // // INSERT, UPDATE, DELETE, QUERY // } // // Path: src/main/java/pers/zr/opensource/magic/dao/order/Order.java // public class Order { // // private String column; // // private OrderType type; // // public Order(String column, OrderType type) { // this.column = column; // this.type = type; // } // // public String getColumn() { // return column; // } // // public OrderType getType() { // return type; // } // } // // Path: src/main/java/pers/zr/opensource/magic/dao/page/Page.java // public class Page { // // private int pageNo; // // private int pageSize; // // public Page(int pageNo, int pageSize) { // this.pageNo = pageNo; // this.pageSize = pageSize; // } // // public int getPageNo() { // return pageNo; // } // // public void setPageNo(int pageNo) { // this.pageNo = pageNo; // } // // public int getPageSize() { // return pageSize; // } // // public void setPageSize(int pageSize) { // this.pageSize = pageSize; // } // } // Path: src/main/java/pers/zr/opensource/magic/dao/action/Query.java import pers.zr.opensource.magic.dao.constants.ActionMode; import pers.zr.opensource.magic.dao.order.Order; import pers.zr.opensource.magic.dao.page.Page; import java.util.List; } if (log.isDebugEnabled()) { log.debug("### [ " + sql + "] ###"); } return this.sql; } @Override public Object[] getParams() { List<Object> paramsList = getConParams(); //paging if(null != page) { int limit = page.getPageSize(); int offset = (page.getPageNo() - 1) * limit; paramsList.add(limit); paramsList.add(offset); } this.params = paramsList.toArray(); return this.params; } @Override
public ActionMode getActionMode() {
rongzhu8888/magic-dao
src/main/java/pers/zr/opensource/magic/dao/matcher/InMatcher.java
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/MatchType.java // public enum MatchType { // // EQUALS("="), // // GREATER(">"), // // LESS("<"), // // NOT_EQUALS("!="), // // GREATER_OR_EQUALS(">="), // // LESS_OR_EQUALS("<="), // // IN("IN"), // // LIKE("LIKE"), // // BETWEEN_AND("BETWEEN ? AND"); // // // public String value; // // MatchType(String value) { // this.value = value; // } // // }
import pers.zr.opensource.magic.dao.constants.MatchType;
package pers.zr.opensource.magic.dao.matcher; /** * Created by zhurong on 2016-4-29. */ public class InMatcher extends Matcher { private Object[] values; public InMatcher(String column, Object[] values) { if(null == values || values.length < 1) { throw new RuntimeException("InMatcher must contains at least one value!"); } this.column = column; this.values = values; } @Override
// Path: src/main/java/pers/zr/opensource/magic/dao/constants/MatchType.java // public enum MatchType { // // EQUALS("="), // // GREATER(">"), // // LESS("<"), // // NOT_EQUALS("!="), // // GREATER_OR_EQUALS(">="), // // LESS_OR_EQUALS("<="), // // IN("IN"), // // LIKE("LIKE"), // // BETWEEN_AND("BETWEEN ? AND"); // // // public String value; // // MatchType(String value) { // this.value = value; // } // // } // Path: src/main/java/pers/zr/opensource/magic/dao/matcher/InMatcher.java import pers.zr.opensource.magic.dao.constants.MatchType; package pers.zr.opensource.magic.dao.matcher; /** * Created by zhurong on 2016-4-29. */ public class InMatcher extends Matcher { private Object[] values; public InMatcher(String column, Object[] values) { if(null == values || values.length < 1) { throw new RuntimeException("InMatcher must contains at least one value!"); } this.column = column; this.values = values; } @Override
public MatchType getMatchType() {