Skip to content

Commit

Permalink
Add getters for private attribs
Browse files Browse the repository at this point in the history
Change methods visibility to allow their overriding
  • Loading branch information
t-dan committed Nov 2, 2015
1 parent 14a72db commit 20008b1
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 36 deletions.
87 changes: 64 additions & 23 deletions main/src/net/sourceforge/cruisecontrol/builders/CMakeBuilder.java
Expand Up @@ -46,9 +46,9 @@
import net.sourceforge.cruisecontrol.CruiseControlException;
import net.sourceforge.cruisecontrol.Progress;
import net.sourceforge.cruisecontrol.gendoc.annotations.Default;
import net.sourceforge.cruisecontrol.gendoc.annotations.ManualChildName;
import net.sourceforge.cruisecontrol.gendoc.annotations.ManualChildName;
import net.sourceforge.cruisecontrol.gendoc.annotations.Required;
import net.sourceforge.cruisecontrol.gendoc.annotations.SkipDoc;
import net.sourceforge.cruisecontrol.gendoc.annotations.SkipDoc;
import net.sourceforge.cruisecontrol.util.DateUtil;
import net.sourceforge.cruisecontrol.util.IO;
import net.sourceforge.cruisecontrol.util.OSEnvironment;
Expand Down Expand Up @@ -115,19 +115,22 @@ public class CMakeBuilder extends Builder {
public void validate() throws CruiseControlException {
super.validate();

final File builddir = getBuildDir();
final File srcroot = getSrcRoot();

/* A top-level CMake file and build directory arguments are required to be defined */
ValidationHelper.assertIsSet(buildDir, "builddir", this.getClass());
ValidationHelper.assertIsSet(srcRoot, "srcroot", this.getClass());
ValidationHelper.assertIsSet(builddir, "builddir", this.getClass());
ValidationHelper.assertIsSet(srcroot, "srcroot", this.getClass());

/* Check the existence of source directory and CMakeLists.txt file in it. */
ValidationHelper.assertExists(srcRoot, "srcroot", this.getClass());
ValidationHelper.assertExists(new File(srcRoot, "CMakeLists.txt"), "srcroot", this.getClass());
ValidationHelper.assertExists(srcroot, "srcroot", this.getClass());
ValidationHelper.assertExists(new File(srcroot, "CMakeLists.txt"), "srcroot", this.getClass());
/* There must not be a file with the name set in buildDir */
ValidationHelper.assertFalse(buildDir.isFile(), "There is file '" + buildDir
ValidationHelper.assertFalse(builddir.isFile(), "There is file '" + builddir
+ "existing, but it is required to be build directory");

/* Validate all the cmake defines */
for (Option option : options) {
for (final Option option : getOptions()) {
ValidationHelper.assertNotEmpty(option.toString(), "option", option.getClass());
}

Expand All @@ -136,18 +139,18 @@ public void validate() throws CruiseControlException {

builder.setCommand("cmake");
/* Options for CMake */
for (Option option : options) {
for (final Option option : getOptions()) {
builder.addOption(option);
}
/* srcRoot - path to CMakeLists.txt */
builder.addPath(srcRoot);
builder.addPath(srcroot);
/* CMake is the very first */
commands.addFirst(builder);

/* Set inherited properties and validate individual commands */
for (ExecBuilder c : commands) {
for (final ExecBuilder c : getBuilders()) {
if (c.getWorkingDir() == null) {
c.setWorkingDir(buildDir.getAbsolutePath());
c.setWorkingDir(builddir.getAbsolutePath());
}
c.setLiveOutput(isLiveOutput());
c.setMultiple(getMultiple());
Expand All @@ -169,19 +172,21 @@ public Element build(final Map<String, String> buildProperties, final Progress p
Element buildLogElement = new Element("build");
Element cmmndLogElement;
Attribute cmndErrAttrib;
File builddir = getBuildDir();

/* If clean directory is required, clean it */
if (cleanBuild) {
IO.delete(buildDir);
if (getCleanBuild()) {
IO.delete(builddir);
}
/* Creates the build directory, if it does not exist. */
if (!buildDir.exists()) {
buildDir.mkdirs();
if (!builddir.exists()) {
builddir.mkdirs();
}

/* Call all the commands one after another */
for (ExecBuilder c : commands) {
long remainTime = timeout != ScriptRunner.NO_TIMEOUT
for (final ExecBuilder c : getBuilders()) {
final long timeout = getTimeout();
final long remainTime = timeout != ScriptRunner.NO_TIMEOUT
? timeout - (System.currentTimeMillis() - startTime) / 1000
: Long.MAX_VALUE;

Expand Down Expand Up @@ -263,6 +268,12 @@ public File getBuildDir() {
public void setCleanBuild(boolean value) {
this.cleanBuild = value;
}
/**
* @return the value set through {@link #setCleanBuild(boolean)}
*/
public boolean getCleanBuild() {
return this.cleanBuild;
}

/**
* Sets the maximum time of the build run [in seconds] from <code>timeout=""</code> attribute. The
Expand All @@ -271,7 +282,13 @@ public void setCleanBuild(boolean value) {
* @param timeout time after which the build is terminated.
*/
public void setTimeout(long timeout) {
this.timeout = timeout;
this.timeOut = timeout;
}
/**
* @return the value set through {@link #setTimeout(long)}
*/
public long getTimeout() {
return this.timeOut;
}

/**
Expand All @@ -280,17 +297,33 @@ public void setTimeout(long timeout) {
*
* @return new object to configure according to the tag values.
*/
public Option createOption() {
public Object createOption() {
options.add(new Option());
return options.getLast();
}
/**
* Adds pre-configured object
* @param obj the pre-configured object (currently only instance of {@link CMakeBuilderOptions} class)
* @throws CruiseControlException
*/
@SkipDoc
public void add(Object obj) throws CruiseControlException {
/* Check the instance */
if (obj instanceof CMakeBuilderOptions) {
/* Add the maps to the list */
add((CMakeBuilderOptions) obj);
return;
}
/* Invalid object */
throw new CruiseControlException("Invalid configuration object: " + obj);
}
/**
* Adds pre-configured set of options which are merged with the current set of options set through {@link
* #createOption()}.
*
* @param optsobj the instance of {@link CMakeBuilderOptions} class
*/
public void add(CMakeBuilderOptions optsobj) {
protected void add(CMakeBuilderOptions optsobj) {
/* Add the options to the list */
for (Option o : optsobj.getOptions()) {
options.add(o);
Expand Down Expand Up @@ -329,6 +362,14 @@ protected ExecBuilderCMake createBuilder() {
return new ExecBuilderCMake();
}

/** Returns iterable through builders created by {@link #createBuild()} */
protected Iterable<ExecBuilderCMake> getBuilders() {
return commands;
}
/** Returns iterable through options created by {@link #createOption()} */
protected Iterable<Option> getOptions() {
return options;
}


/* ----------- ATTRIBS BLOCK ----------- */
Expand All @@ -345,7 +386,7 @@ protected ExecBuilderCMake createBuilder() {
private boolean cleanBuild = false;

/** The maximum time of build run [in sec.]. */
private long timeout;
private long timeOut = 0;

/** The list of <tt>-D</tt> defines passed to <tt>cmake</tt> command. */
private LinkedList<Option> options = new LinkedList<Option>();
Expand All @@ -366,7 +407,7 @@ protected ExecBuilderCMake createBuilder() {
*
* Not that '-' must be the part of option name!
*/
public static final class Option extends StringWriter {
public static class Option extends StringWriter {
/**
* Sets the name of the option.
* @param option string with the define option name.
Expand Down
Expand Up @@ -64,15 +64,15 @@ public EnvConf createEnv() {
* Gets the options set through {@link #createOption()}.
* @return iterator through the sequence of options
*/
Iterable<Option> getOptions() {
public Iterable<Option> getOptions() {
return options;
}

/**
* Gets the env variable set through {@link #createEnv()}.
* @return iterator through the sequence of env values
*/
Iterable<EnvConf> getEnvs() {
public Iterable<EnvConf> getEnvs() {
return envs;
}

Expand Down
Expand Up @@ -114,7 +114,7 @@ public Element build(final Map<String, String> buildProperties, final Progress p
* of the script.
* @return the result of the command.
*/
Element build(final Map<String, String> buildProperties, final Progress progressIn,
public Element build(final Map<String, String> buildProperties, final Progress progressIn,
final InputStream stdinProvider) {

final Progress progress = getShowProgress() ? progressIn : null;
Expand Down Expand Up @@ -219,11 +219,11 @@ private String substituteProperties(final Map<String, String> properties, final
return value;
}

ExecScript createExecScript() {
protected ExecScript createExecScript() {
return new ExecScript();
}

ScriptRunner createScriptRunner() {
protected ScriptRunner createScriptRunner() {
return new ScriptRunner();
}

Expand Down
Expand Up @@ -253,7 +253,7 @@ public boolean runScript(Script script, long timeout, BuildOutputLogger logger)
* @see #runScript(File, Script, long, InputStream, BuildOutputLogger) where the method
* is called.
*/
StreamPumper getOutPumper(final Process p, final StreamConsumer consumer) {
protected StreamPumper getOutPumper(final Process p, final StreamConsumer consumer) {
return new StreamPumper(p.getInputStream(), consumer);
} // getOutPumper

Expand All @@ -268,7 +268,7 @@ StreamPumper getOutPumper(final Process p, final StreamConsumer consumer) {
* @see #runScript(File, Script, long, InputStream, BuildOutputLogger) where the method
* is called.
*/
StreamPumper getErrPumper(final Process p, final StreamConsumer consumer) {
protected StreamPumper getErrPumper(final Process p, final StreamConsumer consumer) {
return new StreamPumper(p.getErrorStream(), consumer);
} // getErrPumper

Expand All @@ -283,7 +283,7 @@ StreamPumper getErrPumper(final Process p, final StreamConsumer consumer) {
* @see #runScript(File, Script, long, InputStream, BuildOutputLogger) where the method
* is called.
*/
StreamPumper getInPumper(final Process p, final InputStream source) {
protected StreamPumper getInPumper(final Process p, final InputStream source) {
return new StreamPumper(source, true, null, p.getOutputStream());
} // getInPumper

Expand All @@ -296,7 +296,7 @@ StreamPumper getInPumper(final Process p, final InputStream source) {
* @see #runScript(File, Script, long, InputStream, BuildOutputLogger) where the method
* is called.
*/
StreamConsumer getDirectOutLogger() {
protected StreamConsumer getDirectOutLogger() {
return StreamLogger.getInfoLogger(LOG);
} // getDirectOutLogger
/**
Expand All @@ -308,7 +308,7 @@ StreamConsumer getDirectOutLogger() {
* @see #runScript(File, Script, long, InputStream, BuildOutputLogger) where the method
* is called.
*/
StreamConsumer getDirectErrLogger() {
protected StreamConsumer getDirectErrLogger() {
return StreamLogger.getWarnLogger(LOG);
} // getDirectErrLogger

Expand All @@ -321,7 +321,7 @@ StreamConsumer getDirectErrLogger() {
* @see #runScript(File, Script, long, InputStream, BuildOutputLogger) where the method
* is called.
*/
boolean letConsumeOut() {
protected boolean letConsumeOut() {
return true;
} // letConsumeOut
/**
Expand All @@ -333,7 +333,7 @@ boolean letConsumeOut() {
* @see #runScript(File, Script, long, InputStream, BuildOutputLogger) where the method
* is called.
*/
boolean letConsumeErr() {
protected boolean letConsumeErr() {
return true;
} // letConsumeErr

Expand Down
Expand Up @@ -392,7 +392,7 @@ CMakeBuilder builderFactory()

/* Child configuration elements */
for (String o : options) {
Option O = builder.createOption();
Option O = (Option) builder.createOption();
/* Set filled items */
if (!"".equals(o))
O.setValue(o);
Expand Down

0 comments on commit 20008b1

Please sign in to comment.