Permalink
Browse files

Simplifying interface so scanning happens automatically

  • Loading branch information...
1 parent b6c8dd7 commit 789275af2929868007c70bb169fbe70829111ea6 @stevearm committed Feb 25, 2012
View
@@ -36,3 +36,15 @@ Assuming syncaws is a script to run `java -jar syncaws.jar --configDir <configDi
3. Upload the new index
4. Upload all new files
5. Update the display files to add the new index as the newest
+
+`syncaws list`
+
+1. List all project names
+
+`syncaws version`
+
+1. Display the version
+
+`syncaws help`
+
+1. Display help
View
@@ -128,6 +128,11 @@
<artifactId>jcommander</artifactId>
<version>1.18</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.1</version>
+ </dependency>
<dependency>
<groupId>com.horsefire</groupId>
@@ -11,55 +11,40 @@
@Parameter(names = { "-c", "--configDir" }, description = "SyncAws config directory")
private String configDir;
- @Parameter(names = { "-p", "--project" }, description = "Project name")
- private String project = null;
-
- @Parameter(names = { "--dir" }, description = "Project directory")
- private String dir = null;
-
@Parameter(names = { "--debug" }, description = "Enable debug logging")
private boolean debug = false;
- @Parameter(names = { "--dry-run" }, description = "Dry run for upload")
- private boolean dryrun = false;
-
@Parameter
- private List<String> tasks = Lists.newArrayList();
+ private List<String> args = Lists.newArrayList();
public CommandLineArgs() {
}
- CommandLineArgs(String configDir, String project, boolean debug,
- List<String> tasks, String dir, boolean dryRun) {
+ CommandLineArgs(String configDir, boolean debug, List<String> args) {
this.configDir = configDir;
- this.project = project;
this.debug = debug;
- this.tasks = tasks;
- this.dryrun = dryRun;
- this.dir = dir;
+ this.args = args;
}
public String getConfigDir() {
return configDir;
}
- public String getProject() {
- return project;
- }
-
- public String getDir() {
- return dir;
- }
-
public boolean isDebug() {
return debug;
}
- public boolean isDryrun() {
- return dryrun;
+ public String getTask() {
+ if (args.size() > 0) {
+ return args.get(0);
+ }
+ return null;
}
- public List<String> getTasks() {
- return Collections.unmodifiableList(tasks);
+ public List<String> getArgs() {
+ if (args.size() > 1) {
+ return Collections.unmodifiableList(args.subList(1, args.size()));
+ }
+ return Collections.emptyList();
}
}
@@ -87,6 +87,15 @@ public String getBaseUrl() {
return Collections.unmodifiableCollection(Arrays.asList(projects));
}
+ public Project getProject(String name) {
+ for (Project project : getConfig().projects) {
+ if (project.getName().equals(name)) {
+ return project;
+ }
+ }
+ return null;
+ }
+
public void addProject(Project project) {
LOG.debug("Adding new project: {}", project);
Project[] projects = new Project[getConfig().projects.length + 1];
@@ -35,17 +35,15 @@ public void run() throws Exception {
return;
}
- Task[] tasks = null;
+ Task task = null;
try {
- tasks = m_taskFactory.parseTasks();
+ task = m_taskFactory.getTask();
} catch (RuntimeException e) {
LOG.error("Error parsing tasks: {}", e.getMessage(), e);
return;
}
try {
- for (Task task : tasks) {
- task.run();
- }
+ task.run();
} catch (RuntimeException e) {
LOG.error("Error running task: {}", e.getMessage(), e);
}
@@ -1,8 +1,5 @@
package com.horsefire.syncaws;
-import java.io.InputStream;
-import java.util.Properties;
-
import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
@@ -29,16 +26,6 @@ public static void main(String[] args) throws Exception {
System.setProperty("log-level", "DEBUG");
}
- if (options.getTasks().size() == 1
- && options.getTasks().get(0).equals("version")) {
- String path = "/META-INF/maven/com.horsefire/syncaws/pom.properties";
- InputStream stream = SyncAws.class.getResourceAsStream(path);
- Properties props = new Properties();
- props.load(stream);
- System.out.println("SyncAws " + props.get("version"));
- return;
- }
-
Driver.start(options);
}
}
@@ -2,6 +2,7 @@
import java.io.File;
import java.io.Reader;
+import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -20,18 +21,18 @@
private static final Logger LOG = LoggerFactory.getLogger(CreateTask.class);
- private final CommandLineArgs m_options;
+ private final CommandLineArgs m_args;
private final ConfigService m_configService;
private final UuidGenerator m_generator;
private final AwsClient m_client;
private final UrlService m_urlService;
private final FileDelegate m_fileDelegate;
@Inject
- public CreateTask(CommandLineArgs options, ConfigService configService,
+ public CreateTask(CommandLineArgs args, ConfigService configService,
UuidGenerator generator, AwsClient client, UrlService urlService,
FileDelegate fileDelegate) {
- m_options = options;
+ m_args = args;
m_configService = configService;
m_generator = generator;
m_client = client;
@@ -40,21 +41,16 @@ public CreateTask(CommandLineArgs options, ConfigService configService,
}
public void validate() {
- String projectName = m_options.getProject();
- if (projectName == null || projectName.isEmpty()) {
+ if (m_args.getArgs().size() != 2) {
throw new RuntimeException(
- "Must specify project name when creating a project");
- }
- String dir = m_options.getDir();
- if (dir == null || dir.isEmpty()) {
- throw new RuntimeException(
- "Must specify dir when creating a project");
+ "Task expects project name and directory");
}
}
public void run() throws Exception {
- String projectName = m_options.getProject();
- File dir = new File(m_options.getDir());
+ List<String> args = m_args.getArgs();
+ String projectName = args.get(0);
+ File dir = new File(args.get(1));
if (!m_fileDelegate.isDirectory(dir)) {
throw new RuntimeException("Directory must exist");
}
@@ -82,7 +78,6 @@ public void run() throws Exception {
m_client.putHtml(htmlFile.toString(), m_urlService.getHtmlFile(project));
m_client.putJson("[]", m_urlService.getIndexList(project));
m_configService.addProject(project);
- LOG.info("Added project {} and uploaded index files",
- m_options.getProject());
+ LOG.info("Added project {} and uploaded index files", projectName);
}
}
@@ -0,0 +1,24 @@
+package com.horsefire.syncaws.tasks;
+
+import com.google.inject.Inject;
+import com.horsefire.syncaws.CommandLineArgs;
+
+public class HelpTask implements Task {
+
+ private final CommandLineArgs m_args;
+
+ @Inject
+ public HelpTask(CommandLineArgs args) {
+ m_args = args;
+ }
+
+ public void validate() {
+ if (!m_args.getArgs().isEmpty()) {
+ throw new RuntimeException("Task does not have arguments");
+ }
+ }
+
+ public void run() throws Exception {
+ throw new UnsupportedOperationException("Help not implemented");
+ }
+}
@@ -1,19 +1,24 @@
package com.horsefire.syncaws.tasks;
import com.google.inject.Inject;
+import com.horsefire.syncaws.CommandLineArgs;
import com.horsefire.syncaws.ConfigService;
public class InitTask implements Task {
+ private final CommandLineArgs m_args;
private final ConfigService m_configService;
@Inject
- public InitTask(ConfigService configService) {
+ public InitTask(CommandLineArgs args, ConfigService configService) {
+ m_args = args;
m_configService = configService;
}
public void validate() {
- // Do nothing
+ if (!m_args.getArgs().isEmpty()) {
+ throw new RuntimeException("Task does not have arguments");
+ }
}
public void run() throws Exception {
@@ -4,25 +4,31 @@
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
+import com.horsefire.syncaws.CommandLineArgs;
import com.horsefire.syncaws.ConfigService;
import com.horsefire.syncaws.Project;
import com.horsefire.syncaws.aws.UrlService;
-public class ViewTask implements Task {
+public class ListTask implements Task {
- private static final Logger LOG = LoggerFactory.getLogger(ViewTask.class);
+ private static final Logger LOG = LoggerFactory.getLogger(ListTask.class);
+ private final CommandLineArgs m_args;
private final ConfigService m_configService;
private final UrlService m_urlService;
@Inject
- public ViewTask(ConfigService configService, UrlService urlService) {
+ public ListTask(CommandLineArgs args, ConfigService configService,
+ UrlService urlService) {
+ m_args = args;
m_configService = configService;
m_urlService = urlService;
}
public void validate() {
- // Do nothing
+ if (!m_args.getArgs().isEmpty()) {
+ throw new RuntimeException("Task does not have arguments");
+ }
}
public void run() throws Exception {
@@ -1,40 +0,0 @@
-package com.horsefire.syncaws.tasks;
-
-import com.horsefire.syncaws.CommandLineArgs;
-import com.horsefire.syncaws.ConfigService;
-import com.horsefire.syncaws.Project;
-
-public abstract class ProjectTask implements Task {
-
- private final CommandLineArgs m_options;
- private final ConfigService m_configService;
- private Project m_selectedProject;
-
- public ProjectTask(CommandLineArgs options, ConfigService configService) {
- m_options = options;
- m_configService = configService;
- }
-
- protected CommandLineArgs getOptions() {
- return m_options;
- }
-
- protected ConfigService getConfig() {
- return m_configService;
- }
-
- protected Project getSelectedProject() {
- return m_selectedProject;
- }
-
- public void validate() {
- for (Project project : getConfig().getProjects()) {
- if (project.getName().equals(getOptions().getProject())) {
- m_selectedProject = project;
- return;
- }
- }
- throw new RuntimeException("No project found for: "
- + m_options.getProject());
- }
-}
Oops, something went wrong.

0 comments on commit 789275a

Please sign in to comment.