|
From: <tre...@us...> - 2007-09-06 13:16:25
|
Revision: 375
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=375&view=rev
Author: trevorolio
Date: 2007-09-06 06:16:29 -0700 (Thu, 06 Sep 2007)
Log Message:
-----------
Improved the account checks when accepting or denying space modifications via web api.
Avoided a null pointer exception in populate mojo when the populate dir was not configured.
Modified Paths:
--------------
maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java
maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java
Modified: maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java
===================================================================
--- maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java 2007-09-06 13:16:24 UTC (rev 374)
+++ maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java 2007-09-06 13:16:29 UTC (rev 375)
@@ -17,82 +17,80 @@
public abstract class OgServiceMojoBase extends AbstractMojo {
protected static final String SPACE_PREFIX = "space-";
- protected static final String TEMPLATE_PREFIX = "template-";
- /**
- * @parameter
- */
- protected File populateDir;
- /**
- * @parameter
- */
- protected String serviceURI;
- /**
- * @parameter
- */
- protected String username;
- /**
- * @parameter
- */
- private String password;
- protected WebAPIClient validateArgsAndConnect() {
- if (populateDir == null) {
- getLog().info("No populate baseDir given. Mojo ignored.");
- return null;
- }
-
- if ((!populateDir.exists()) || (!populateDir.isDirectory())
- || (!populateDir.canRead())) {
- getLog().error(
- "Unable to access base dir:" + populateDir.getAbsolutePath());
- return null;
- }
-
- if (serviceURI == null) {
- getLog().info("No populate serviceURI given. Mojo ignored.");
- return null;
- }
- try {
- WebAPIClientWire wire = new WebAPIClientWire();
- WebAPIDescriptor descriptor = new WebAPIDescriptor(new URI(
- serviceURI));
- WebAPIAuthenticator auth = new WebAPIAuthenticator(wire,
- descriptor, username, password);
- WebAPIClient client = new WebAPIClient(descriptor, auth, wire);
- return client;
-
- } catch (URISyntaxException e) {
- getLog().error("Bad URI (" + serviceURI + ")", e);
- } catch (IOException e) {
- getLog().error("Unable to connect to service (" + serviceURI + ")",
- e);
- }
- // some kind of exception
- return null;
- }
+ protected static final String TEMPLATE_PREFIX = "template-";
- protected TemplateDocument fileNameToTemplateDocument(WebAPIClient client, File tempFile)
- throws IOException {
- String templateName = fileToTemplateName(tempFile);//.obj
- TemplateDocument doc = client.createTemplate(templateName);
- return doc;
- }
+ /**
+ * @parameter
+ */
+ protected File populateDir;
- protected String fileToTemplateName(File tempFile) {
- return tempFile.getName().substring(0, tempFile.getName().length() - 4);
- }
+ /**
+ * @parameter
+ */
+ protected String serviceURI;
- protected int dirNameToTemplateNumber(File candidate)
- throws MojoExecutionException {
- int n = -188;
- String num = candidate.getName().substring(TEMPLATE_PREFIX.length());
- try {
- n = Integer.parseInt(num);
- } catch (NumberFormatException e) {
- throw new MojoExecutionException("Badly formed template name in populate directory:"+candidate.getName());
- }
- return n;
-
- }
+ /**
+ * @parameter
+ */
+ protected String username;
+ /**
+ * @parameter
+ */
+ private String password;
+
+ protected WebAPIClient validateArgsAndConnect() {
+ if (populateDir == null) {
+ getLog().info("No populate baseDir given. Mojo ignored.");
+ return null;
+ }
+
+ if ((!populateDir.exists()) || (!populateDir.isDirectory()) || (!populateDir.canRead())) {
+ getLog().error("Unable to access base dir:" + populateDir.getAbsolutePath());
+ return null;
+ }
+
+ if (serviceURI == null) {
+ getLog().info("No populate serviceURI given. Mojo ignored.");
+ return null;
+ }
+ try {
+ WebAPIClientWire wire = new WebAPIClientWire();
+ WebAPIDescriptor descriptor = new WebAPIDescriptor(new URI(serviceURI));
+ WebAPIAuthenticator auth = new WebAPIAuthenticator(wire, descriptor, username, password);
+ WebAPIClient client = new WebAPIClient(descriptor, auth, wire);
+ return client;
+
+ } catch (URISyntaxException e) {
+ getLog().error("Bad URI (" + serviceURI + ")", e);
+ } catch (IOException e) {
+ getLog().error("Unable to connect to service (" + serviceURI + ")", e);
+ }
+ // some kind of exception
+ return null;
+ }
+
+ protected TemplateDocument fileNameToTemplateDocument(WebAPIClient client, File tempFile) throws IOException {
+ String templateName = fileToTemplateName(tempFile);//.obj
+ TemplateDocument doc = client.createTemplate(templateName);
+ return doc;
+ }
+
+ protected String fileToTemplateName(File tempFile) {
+ return tempFile.getName().substring(0, tempFile.getName().length() - 4);
+ }
+
+ protected int dirNameToTemplateNumber(File candidate) throws MojoExecutionException {
+ int n = -188;
+ String num = candidate.getName().substring(TEMPLATE_PREFIX.length());
+ try {
+ n = Integer.parseInt(num);
+ } catch (NumberFormatException e) {
+ throw new MojoExecutionException("Badly formed template name in populate directory:" + candidate.getName());
+ }
+ return n;
+
+ }
+
}
Modified: maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java
===================================================================
--- maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java 2007-09-06 13:16:24 UTC (rev 374)
+++ maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java 2007-09-06 13:16:29 UTC (rev 375)
@@ -30,7 +30,9 @@
public void execute() throws MojoExecutionException {
WebAPIClient client = validateArgsAndConnect();
-
+ if(client == null){
+ return;
+ }
File[] templates = populateDir.listFiles();
for (int i = 0; i < templates.length; ++i) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|