X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fmain%2FCLI.java;h=627517c97e11dae081ae8615f914e23111e12160;hb=1996f683a8e4101e7f3d57e2137cc4f22a342f09;hp=1533c11feab4b95c8df26a0460d1d4b3025b676d;hpb=e4f461213da0e30faf9e9eb2e97626abff320618;p=jSite.git diff --git a/src/de/todesbaum/jsite/main/CLI.java b/src/de/todesbaum/jsite/main/CLI.java index 1533c11..627517c 100644 --- a/src/de/todesbaum/jsite/main/CLI.java +++ b/src/de/todesbaum/jsite/main/CLI.java @@ -21,7 +21,6 @@ package de.todesbaum.jsite.main; import java.io.PrintWriter; -import de.todesbaum.jsite.application.EditionProject; import de.todesbaum.jsite.application.Freenet7Interface; import de.todesbaum.jsite.application.InsertListener; import de.todesbaum.jsite.application.Node; @@ -29,20 +28,42 @@ import de.todesbaum.jsite.application.Project; import de.todesbaum.jsite.application.ProjectInserter; /** - * @author David Roden <droden@gmail.com> - * @version $Id$ + * Command-line interface for jSite. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ public class CLI implements InsertListener { + /** Object used for synchronization. */ private Object lockObject = new Object(); + + /** Writer for the console. */ private PrintWriter outputWriter = new PrintWriter(System.out, true); + + /** The freenet interface. */ private Freenet7Interface freenetInterface; + + /** The project inserter. */ private ProjectInserter projectInserter = new ProjectInserter(); + + /** The list of nodes. */ private Node[] nodes; + + /** The projects. */ private Project[] projects; + + /** Whether the insert has finished. */ private boolean finished = false; + + /** Whether the insert finished successfully. */ private boolean success; + /** + * Creates a new command-line interface. + * + * @param args + * The command-line arguments + */ private CLI(String[] args) { if ((args.length == 0) || args[0].equals("-h") || args[0].equals("--help")) { @@ -75,7 +96,7 @@ public class CLI implements InsertListener { projectInserter.setFreenetInterface(freenetInterface); Project currentProject = null; - for (String argument: args) { + for (String argument : args) { String value = argument.substring(argument.indexOf('=') + 1).trim(); if (argument.startsWith("--node=")) { Node newNode = getNode(value); @@ -115,12 +136,7 @@ public class CLI implements InsertListener { outputWriter.println("You can't specify --edition before --project."); return; } - if (currentProject instanceof EditionProject) { - ((EditionProject) currentProject).setEdition(Integer.parseInt(value)); - } else { - outputWriter.println("Project \"" + currentProject.getName() + "\" is not an edition-based project."); - return; - } + currentProject.setEdition(Integer.parseInt(value)); } else { outputWriter.println("Unknown parameter: " + argument); return; @@ -139,8 +155,15 @@ public class CLI implements InsertListener { configuration.save(); } + /** + * Returns the project with the given name. + * + * @param name + * The name of the project + * @return The project, or null if no project could be found + */ private Project getProject(String name) { - for (Project project: projects) { + for (Project project : projects) { if (project.getName().equals(name)) { return project; } @@ -148,8 +171,15 @@ public class CLI implements InsertListener { return null; } + /** + * Returns the node with the given name. + * + * @param name + * The name of the node + * @return The node, or null if no node could be found + */ private Node getNode(String name) { - for (Node node: nodes) { + for (Node node : nodes) { if (node.getName().equals(name)) { return node; } @@ -157,6 +187,14 @@ public class CLI implements InsertListener { return null; } + /** + * Inserts the given project. + * + * @param currentProject + * The project to insert + * @return true if the insert finished successfully, + * false otherwise + */ private boolean insertProject(Project currentProject) { if (!freenetInterface.hasNode()) { outputWriter.println("Node is not running!"); @@ -169,6 +207,7 @@ public class CLI implements InsertListener { try { lockObject.wait(); } catch (InterruptedException e) { + /* ignore, we're in a loop. */ } } } @@ -186,6 +225,9 @@ public class CLI implements InsertListener { outputWriter.println("Starting Insert of project \"" + project.getName() + "\"."); } + /** + * {@inheritDoc} + */ public void projectURIGenerated(Project project, String uri) { outputWriter.println("URI: " + uri); } @@ -203,11 +245,6 @@ public class CLI implements InsertListener { public void projectInsertFinished(Project project, boolean success, Throwable cause) { outputWriter.println("Request URI: " + project.getFinalRequestURI(0)); finished = true; - if (success) { - if (project instanceof EditionProject) { - ((EditionProject) project).setEdition(((EditionProject) project).getEdition() + 1); - } - } this.success = success; synchronized (lockObject) { lockObject.notify(); @@ -218,6 +255,12 @@ public class CLI implements InsertListener { // MAIN // + /** + * Creates a new command-line interface with the given arguments. + * + * @param args + * The command-line arguments + */ public static void main(String[] args) { new CLI(args); }