/*
* #%L
* restdoc-plugin
* %%
* Copyright (C) 2012 IG Group
* %%
* 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.
* #L%
*/
package com.iggroup.oss.restdoclet.plugin.io;
import static com.iggroup.oss.restdoclet.plugin.util.MavenUtils.TARGET_DIR;
import java.io.File;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
/**
* This class contains the <code>target</code> directories of the module
* RestDocumentationMojo is running on.
*/
public class DirectoryBuilder {
/**
* The name of <code>/WEB-INF/classes</code> directory.
*/
public static final String CLASSES_DIR = "classes";
/**
* Base-directory of the module RestDocumentationMojo is running on.
*/
private File baseDirectory;
/**
* Target-directory of the module RestDocumentationMojo is running on.
*/
private File targetDirectory;
/**
* The directory containing classes of the generated web-application.
*/
private File classesDirectory;
/**
* Constructs the <code>target</code> directories with the base-directory of
* the module RestDocumentationMojo is running on.
*
* @param baseDirectory the base-directory of the module.
* @param output the output-directory of the web-application generated by
* documentation. It is set to <code>restdoc</code> by default.
*/
public DirectoryBuilder(final File baseDirectory, final String output) {
this.baseDirectory = baseDirectory;
initTargetDirectory();
initClassesDirectory(output);
}
/**
* Initialises the target-directory.
*/
private void initTargetDirectory() {
targetDirectory = new File(baseDirectory, TARGET_DIR);
targetDirectory.mkdir();
}
/**
* Initialises the directory containing the classes.
*/
private void initClassesDirectory(final String output) {
classesDirectory =
new File(targetDirectory, CLASSES_DIR + File.separatorChar + output);
classesDirectory.mkdir();
}
/**
* Gets the base-directory.
*
* @return the base-directory.
*/
public File getBaseDirectory() {
return baseDirectory;
}
/**
* Sets the base-directory.
*
* @param baseDirectory the base directory.
*/
public void setBaseDirectory(final File baseDirectory) {
this.baseDirectory = baseDirectory;
}
/**
* Gets the target-directory.
*
* @return the target-directory.
*/
public File getTargetDirectory() {
return targetDirectory;
}
/**
* Sets the target-directory. This operation is not supported.
*
* @param targetDirectory the target-directory.
*/
public void setTargetDirectory(final File targetDirectory) {
throw new UnsupportedOperationException(
"DirectoryBuilder.setTargetDirectory(File)");
}
/**
* Sets the output-directory. This operation is not supported.
*
* @param outputDirectory the output-directory.
*/
public void setOutputDirectory(final File outputDirectory) {
throw new UnsupportedOperationException(
"DirectoryBuilder.setOutputDirectory(File)");
}
/**
* Gets the directory containing the classes.
*
* @return the directory containing the classes.
*/
public File getClassesDirectory() {
return classesDirectory;
}
/**
* Sets the directory containing the classes.
*
* @param classesDirectory the directory containing the classes.
*/
public void setClassesDirectory(final File classesDirectory) {
throw new UnsupportedOperationException(
"DirectoryBuilder.setClassesDirectory(File)");
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("targetDirectory", targetDirectory).toString();
}
}