Skip to content

Commit

Permalink
#782: Introduce a system property to denote if hawtio is offline mode…
Browse files Browse the repository at this point in the history
… or not. This allows us to use the full WAR in maven plugin but just run some mbeans in offline mode.
  • Loading branch information
davsclaus committed Nov 30, 2013
1 parent 7e97f73 commit 99142a7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions hawtio-core/src/main/java/io/hawt/config/ConfigFacade.java
Expand Up @@ -74,4 +74,8 @@ public void setConfigDir(String configDir) {
this.configDir = configDir;
}

public boolean isOffline() {
return "true".equals(System.getProperty("hawtio.offline", "false"));
}

}
10 changes: 9 additions & 1 deletion hawtio-git/src/main/java/io/hawt/git/GitFacade.java
Expand Up @@ -57,6 +57,7 @@ public class GitFacade extends GitFacadeSupport {
private PersonIdent stashPersonIdent;
private String defaultBranch;
private boolean firstPull = true;
private ConfigFacade config;

public static String trimLeadingSlash(String path) {
String name = path;
Expand All @@ -66,8 +67,15 @@ public static String trimLeadingSlash(String path) {
return name;
}


public void init() throws Exception {
config = ConfigFacade.getSingleton();

if (config.isOffline()) {
// lets avoid cloning or pulling the remote git repo for configuration on startup if offline mode
cloneRemoteRepoOnStartup = false;
pullOnStartup = false;
}

// lets check if we have a config directory if not lets create one...
initialiseGitRepo();

Expand Down
Expand Up @@ -6,6 +6,7 @@
import javax.management.MBeanServer;
import javax.management.ObjectName;

import io.hawt.config.ConfigFacade;
import io.hawt.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -25,8 +26,16 @@ public class AsyncMavenIndexerFacadeFactory {
private String indexDirectory;
private Timer timer;
private TimerTask task;
private ConfigFacade config;

public void init() {
config = ConfigFacade.getSingleton();

if (config.isOffline()) {
LOG.info("MavenIndexerFacade is not in use as hawtio is in offline mode");
return;
}

timer = new Timer("MavenIndexerFacade startup timer", true);
task = new TimerTask() {
@Override
Expand Down
14 changes: 14 additions & 0 deletions hawtio-maven-plugin/src/main/java/io/hawt/maven/BaseMojo.java
Expand Up @@ -69,9 +69,23 @@ public abstract class BaseMojo extends AbstractMojo {
@Parameter(property = "hawtio.logDependencies", defaultValue = "false")
boolean logDependencies;

@Parameter(property = "hawtio.offline", defaultValue = "false")
boolean offline;

String extraPluginDependencyArtifactId;
String extendedPluginDependencyArtifactId;

protected void doBeforeExecute() {
if (offline) {
getLog().info("hawtio is running in offline mode");
System.setProperty("hawtio.offline", "true");
}
}

protected void doAfterExecute() {
System.clearProperty("hawtio.offline");
}

/**
* Set up a classloader for the execution of the main class.
*
Expand Down
4 changes: 4 additions & 0 deletions hawtio-maven-plugin/src/main/java/io/hawt/maven/RunMojo.java
Expand Up @@ -36,12 +36,16 @@ public void execute() throws MojoExecutionException, MojoFailureException {

try {
doPrepareArguments();
doBeforeExecute();
doExecute();
doAfterExecute();
} catch (Exception e) {
throw new MojoExecutionException("Error executing", e);
}
}



protected void doPrepareArguments() throws Exception {
List<String> args = new ArrayList<String>();

Expand Down

0 comments on commit 99142a7

Please sign in to comment.