Skip to content

Commit

Permalink
Maven: Fix bug with reloading from json file
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Forslund committed Jun 13, 2016
1 parent d15455a commit 619c79e
Showing 1 changed file with 13 additions and 5 deletions.
Expand Up @@ -22,6 +22,7 @@
import com.speedment.runtime.component.Component;
import com.speedment.runtime.internal.runtime.DefaultApplicationBuilder;
import com.speedment.tool.internal.component.UserInterfaceComponentImpl;
import static com.speedment.tool.internal.util.ConfigFileHelper.DEFAULT_CONFIG_LOCATION;
import java.io.File;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -33,6 +34,7 @@
*/
abstract class AbstractSpeedmentMojo extends AbstractMojo {

private final static File DEFAULT_CONFIG = new File(DEFAULT_CONFIG_LOCATION);
private final SpeedmentBuilder<?, ?> builder;

protected abstract File configLocation();
Expand All @@ -52,16 +54,20 @@ public final void execute() throws MojoExecutionException, MojoFailureException
}

protected final boolean hasConfigFile() {
if (configLocation() == null) {
return hasConfigFile(configLocation());
}

protected final boolean hasConfigFile(File file) {
if (file == null) {
final String err = "The specified .json-file is null.";
getLog().error(err);
return false;
} else if (!configLocation().exists()) {
final String err = "The specified .json-file '" + configLocation().getAbsolutePath() + "' does not exist.";
} else if (!file.exists()) {
final String err = "The specified .json-file '" + file.getAbsolutePath() + "' does not exist.";
getLog().error(err);
return false;
} else if (!configLocation().canRead()) {
final String err = "The specified .json-file '" + configLocation().getAbsolutePath() + "' is not readable.";
} else if (!file.canRead()) {
final String err = "The specified .json-file '" + file.getAbsolutePath() + "' is not readable.";
getLog().error(err);
return false;
} else return true;
Expand All @@ -72,6 +78,8 @@ protected final boolean hasConfigFile() {

if (hasConfigFile()) {
result = new DefaultApplicationBuilder(configLocation());
} else if (hasConfigFile(DEFAULT_CONFIG)) {
result = new DefaultApplicationBuilder(DEFAULT_CONFIG);
} else {
result = new DefaultApplicationBuilder();
}
Expand Down

0 comments on commit 619c79e

Please sign in to comment.