krysalis-update/src/java/org/krysalis/depot/update/ant AntUtils.java,NONE,1.1
Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:09:49 +0000
| Newsgroups | gmane.comp.krysalis.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/ant
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26022/src/java/org/krysalis/depot/update/ant
Added Files:
AntUtils.java
Log Message:
move
--- NEW FILE: AntUtils.java ---
/*
* ========================================================================
* Copyright 2004 The Apache Software Foundation
*
* Licensed 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 org.krysalis.depot.update.ant;
import java.io.File;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
/**
* A static collection of AntUtils
*/
public class AntUtils {
/**
* Private constructor for static class
*
*/
private AntUtils() {
}
/**
* validate and create a dir if needed. Ignore if dir is null
*
* @param dir
* @param name
* @param failOnError
* @throws BuildException
* if dir is not a Directory or can not be created
*/
public static void createAndValidateDir(Project p, File dir,
final String name, boolean failOnError) throws BuildException {
if (dir != null) {
if (!dir.exists()) {
if (!dir.mkdirs()) {
final String message = "Could not create dir for " + name
+ " at " + dir.getAbsolutePath();
if (failOnError) {
throw new BuildException(message);
} else {
p.log(message, Project.MSG_WARN);
}
}
} else if (!dir.isDirectory()) {
throw new BuildException(name + " at " + dir.getAbsolutePath()
+ " is not a directroy");
}
}
}
/**
* create/validate the user.home.
*
* @param project
* @return File a valid user home dir or null
*/
public static File getUserHome(Project project) {
return findAndCreateDirFromProperty(project, "user.home");
}
/**
* @return
*/
public static File getDepotHome(Project p) {
File depotHome = findAndCreateDirFromProperty(p, "depot.home");
if (depotHome == null) {
File userHome = getUserHome(p);
depotHome = new File(userHome, ".apache.depot");
createAndValidateDir(p, depotHome, "${user.home}/.apache.depot",
true);
}
if (depotHome == null) {
throw new BuildException("The property depot.home must be set");
}
return depotHome;
}
/**
* find a property and then create and validate it
*
* @param p
* the ant Project
* @param dirProperty
* the property that has the dir path
* @return the dir, created if possille, null if not
*/
public static File findAndCreateDirFromProperty(Project p,
String dirProperty) {
String antletsDirName = p.getProperty(dirProperty);
File antletsDir = null;
if (null == antletsDirName) {
p.log(dirProperty + " not defined.", Project.MSG_DEBUG);
} else {
antletsDir = new File(antletsDirName);
if (!antletsDir.exists()) {
p.log("Unable to create dir " + antletsDir.getAbsolutePath(),
Project.MSG_WARN);
antletsDir = null;
} else if (!antletsDir.isDirectory()) {
throw new BuildException("Property ${" + dirProperty + "} -> ["
+ antletsDir.getAbsolutePath()
+ "] not a workable directory.");
} else {
p.log(dirProperty + " =" + antletsDir, Project.MSG_DEBUG);
}
}
return antletsDir;
}
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/