Skip to content

Commit

Permalink
Merge pull request #3 from AngelsCheeseBurgerOrg/develop
Browse files Browse the repository at this point in the history
For First Release of "makeamove-site-0.0.1-SNAPSHOT-spring-boot"
  • Loading branch information
angelsburger90 authored Oct 20, 2020
2 parents 5268891 + 1b74244 commit 552fbd5
Show file tree
Hide file tree
Showing 15 changed files with 392 additions and 34 deletions.
14 changes: 12 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="output" path="classes"/>
</classpath>
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/bin/
/target/
/classes/
6 changes: 6 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
6 changes: 6 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
131 changes: 131 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.angelssoftware</groupId>
<artifactId>makeamove-site</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Make a Move</name>
<description>Dont make your computer Idle</description>
<build>
<sourceDirectory>src</sourceDirectory>

<!-- Automate to create a bat script that writes runnable jar execution -->
<resources>
<resource>
<directory>resources/build</directory>
<filtering>true</filtering>
<includes>
<include>**/run_make_a_move.bat</include>
</includes>
</resource>
<resource>
<directory>resources/build</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/run_make_a_move.bat</exclude>
</excludes>
</resource>
</resources>

<plugins>

<!-- Always clean project first -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>target</directory>
</fileset>
</filesets>
</configuration>
</plugin>

<!-- Source code Compiler -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<!-- Create Executable/Runnable Jar file as a release process -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.4.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>
org.angelssoftware.MakeaMove
</mainClass>
</configuration>
</execution>
</executions>
</plugin>

<!--
Try to Auto generate the script batch file to execute
the Runnable Jar
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/</outputDirectory>
<resources>
<resource>
<directory>${basedir}/target/classes/</directory>
<includes>
<include>run_make_a_move.bat</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<developers>
<developer>
<id>ryanseth</id>
<name>Ryan Seth Roldan</name>
<email>ryan.s.roldan@gmail.com</email>
<organization>Angels Software</organization>
</developer>
</developers>

<dependencies>
<dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<version>2.33</version>
</dependency>
</dependencies>
<url>https://github.com/AngelsCheeseBurgerOrg/MakeaMove</url>
<organization>
<name>Angels Software Org</name>
<url>https://github.com/AngelsCheeseBurgerOrg</url>
</organization>
</project>
4 changes: 4 additions & 0 deletions resources/build/run_make_a_move.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo ON
"${java.home}\\bin\java" -jar ${project.build.finalName}-spring-boot.jar -mouse-direction UP -execution-period 20000 -mouse-hop-px 1

@pause
9 changes: 0 additions & 9 deletions src/org/angelssoftware/MakeaMove.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
package org.angelssoftware;

import java.awt.AWTException;

import org.angelssoftware.classes.MousePointerMover;
import org.angelssoftware.classes.RobotAutomation;
import org.angelssoftware.models.ApplicationArgumentModel;
import org.angelssoftware.structures.MoveDirection;

public class MakeaMove {

public static void main(String[] args) {
ApplicationArgumentModel applicationArgumentModel = new ApplicationArgumentModel(args);
performASimpleMove(applicationArgumentModel);
}


private static void performASimpleMove(ApplicationArgumentModel applicationArgumentModel) {
try {
applicationArgumentModel.setTimeDelayInMillis(1000);

MousePointerMover mousePointer = new MousePointerMover(applicationArgumentModel);
mousePointer.setMoveDirection(MoveDirection.DOWN);
mousePointer.setMouseHopInPx(3);

RobotAutomation robotAutomation = new RobotAutomation(applicationArgumentModel);
robotAutomation.addRobotAction(mousePointer);
robotAutomation.runRobotActions();
Expand Down
14 changes: 9 additions & 5 deletions src/org/angelssoftware/classes/MousePointerMover.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package org.angelssoftware.classes;

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
import java.awt.Toolkit;

import org.angelssoftware.interfaces.RobotActionInterface;
import org.angelssoftware.interfaces.RobotMouseInterface;
import org.angelssoftware.models.RobotProperties;
import org.angelssoftware.structures.ScreenSize;

public class MousePointerMover extends RobotProperties implements RobotActionInterface, RobotMouseInterface{
private int maxHeight;
Expand All @@ -27,9 +26,9 @@ public MousePointerMover(RobotMouseInterface robotProperties) throws AWTExceptio
}

private void commonInitialization() throws AWTException {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setMaxHeight(screenSize.height);
setMaxWidth(screenSize.width);
ScreenSize screenSize = ScreenSize.getInstance();
setMaxHeight(screenSize.getMaxHeight());
setMaxWidth(screenSize.getMaxWidth());
setLocalRobot(new Robot());
}

Expand Down Expand Up @@ -91,4 +90,9 @@ private Robot getLocalRobot() {
private void setLocalRobot(Robot localRobot) {
this.localRobot = localRobot;
}

@Override
public String toString() {
return "Screensize: x=" + getMaxWidth() + ", y=" + getMaxHeight();
}
}
24 changes: 12 additions & 12 deletions src/org/angelssoftware/classes/RobotAutomation.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ public void runRobotActions() {
Timer timer = new Timer();

//delay - delay in milliseconds before task is to be executed.
long delay = applicationArgumentModel.getTimeDelayInMillis();
long delay = 100;
//period - time in milliseconds between successive task executions.
long period = 1000; //applicationArgumentModel.getTimeDelayInMillis();
long period = applicationArgumentModel.getTimeDelayInMillis();

TimerTask timerTask = new TimerTask() {
@Override
public void run() {
for(RobotActionInterface robotIf : listRobotActions) {
robotIf.action();
}
}
};

timer.schedule(timerTask, delay, period);
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
for(RobotActionInterface robotIf : listRobotActions) {
robotIf.action();
}
}
};
timer.schedule(timerTask, delay, period);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.angelssoftware.interfaces;

import org.angelssoftware.structures.MoveDirection;

public interface RobotPropertiesInterface {
public int getTimeDelayInMillis();
public void setTimeDelayInMillis(int timeDelayInMillis);
Expand Down
86 changes: 84 additions & 2 deletions src/org/angelssoftware/models/ApplicationArgumentModel.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,96 @@
package org.angelssoftware.models;

import java.util.ArrayList;
import java.util.List;

import org.angelssoftware.structures.MoveDirection;
import org.angelssoftware.utilities.StringUtils;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.OptionHandlerFilter;

public class ApplicationArgumentModel extends RobotProperties{

private String[] originalArguments;
@Argument
private List<String> arguments = new ArrayList<String>();

@Option(name="-mouse-direction",aliases="-m-d",
usage="Set the Mouse Direction you want wherein the movement automation will apply. "
+ "Possible values are UP, DOWN, LEFT, RIGHT."
+ "Default is UP")
private String mouseDirectionArg;

@Option(name="-execution-period",aliases="-e",
usage="Defines the timing of execution in milliseconds. "
+ "System will continously trigger the next execution after the defined period (similar to delay execution)."
+ "Default is 20,000 (20 seconds)")
private int executionPeriodArg;

@Option(name="-mouse-hop-px",aliases="-mpx",
usage="Defines the number of pixels the mouse will move to in the automation. "
+ "Default is 1 pixel")
private int mouseHopInPxArg;

public ApplicationArgumentModel(String[] args) {
originalArguments = args.clone();
CmdLineParser parser = new CmdLineParser(this);

try {
// parse the arguments.
parser.parseArgument(args);
matchSetTheArguments();
} catch( CmdLineException e ) {
// if there's a problem in the command line,
// you'll get this exception. this will report
// an error message.
System.err.println(e.getMessage());
System.err.println("java SampleMain [options...] arguments...");
// print the list of available options
parser.printUsage(System.err);
System.err.println();

// print option sample. This is useful some time
System.err.println(" Example: java SampleMain"+parser.printExample(OptionHandlerFilter.ALL, null));

return;
}
}

private void matchSetTheArguments() {
if(!(executionPeriodArg <=0)) setTimeDelayInMillis(executionPeriodArg);
if(!(mouseHopInPxArg <=0)) setMouseHopInPx(mouseHopInPxArg);
setMoveDirection(getMoveDirection(mouseDirectionArg));
}

public MoveDirection getMoveDirection(String mouseDirectionArg) {
if(StringUtils.isNullOrWhiteSpace(mouseDirectionArg)) return MoveDirection.UP;
mouseDirectionArg = mouseDirectionArg.trim().toUpperCase();
for (MoveDirection direction : MoveDirection.values()) {
if(direction.toString().equalsIgnoreCase(mouseDirectionArg)) {
return direction;
}
}
return MoveDirection.UP;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();

sb.append("Args mouseDirectionArg: " + mouseDirectionArg);
sb.append(System.lineSeparator());
sb.append("Args executionPeriodArg: " + executionPeriodArg);
sb.append(System.lineSeparator());
sb.append("Args mouseHopInPxArg: " + mouseHopInPxArg);
sb.append(System.lineSeparator());
sb.append("~~~ Other arguments are:");
sb.append(System.lineSeparator());

for( String s : arguments ) {
sb.append(s);
sb.append(System.lineSeparator());
}
return sb.toString();
}
}
Loading

0 comments on commit 552fbd5

Please sign in to comment.