Skip to content

Commit

Permalink
OpenLiberty#3: Split server task into operation-specific tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
MisaelSalcido committed Sep 29, 2015
1 parent efb665d commit f0c1643
Show file tree
Hide file tree
Showing 11 changed files with 897 additions and 442 deletions.
908 changes: 476 additions & 432 deletions src/main/java/net/wasdev/wlp/ant/ServerTask.java

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src/main/java/net/wasdev/wlp/ant/servertasks/ServerCreate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* (C) Copyright IBM Corporation 2014, 2015.
*
* 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 net.wasdev.wlp.ant.servertasks;

import org.apache.tools.ant.BuildException;

import net.wasdev.wlp.ant.ServerTask;

public class ServerCreate extends ServerTask {
@Override
public void execute() {
initTask();

try {
doCreate();
} catch (Exception e) {
throw new BuildException(e);
}
}
}
40 changes: 40 additions & 0 deletions src/main/java/net/wasdev/wlp/ant/servertasks/ServerDebug.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* (C) Copyright IBM Corporation 2014, 2015.
*
* 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 net.wasdev.wlp.ant.servertasks;

import java.util.List;

import org.apache.tools.ant.BuildException;

import net.wasdev.wlp.ant.ServerTask;

public class ServerDebug extends ServerTask {
@Override
public void execute() {
initTask();

try {
List<String> command = getInitialCommand("debug");
addCleanOption(command);
processBuilder.command(command);
Process p = processBuilder.start();
checkReturnCode(p, processBuilder.command().toString(), ReturnCode.OK.getValue());

} catch (Exception e) {
throw new BuildException(e);
}
}
}
41 changes: 41 additions & 0 deletions src/main/java/net/wasdev/wlp/ant/servertasks/ServerDump.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* (C) Copyright IBM Corporation 2014, 2015.
*
* 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 net.wasdev.wlp.ant.servertasks;

import java.util.List;

import org.apache.tools.ant.BuildException;

import net.wasdev.wlp.ant.ServerTask;

public class ServerDump extends ServerTask {
@Override
public void execute() {
initTask();

try {
List<String> command = getInitialCommand("dump");
addArchiveOption(command);
addIncludeOption(command);
processBuilder.command(command);
Process p = processBuilder.start();
checkReturnCode(p, processBuilder.command().toString(), ReturnCode.OK.getValue());

} catch (Exception e) {
throw new BuildException(e);
}
}
}
40 changes: 40 additions & 0 deletions src/main/java/net/wasdev/wlp/ant/servertasks/ServerJavaDump.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* (C) Copyright IBM Corporation 2014, 2015.
*
* 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 net.wasdev.wlp.ant.servertasks;

import java.util.List;

import org.apache.tools.ant.BuildException;

import net.wasdev.wlp.ant.ServerTask;

public class ServerJavaDump extends ServerTask {
@Override
public void execute() {
initTask();

try {
List<String> command = getInitialCommand("javadump");
addIncludeOption(command);
processBuilder.command(command);
Process p = processBuilder.start();
checkReturnCode(p, processBuilder.command().toString(), ReturnCode.OK.getValue());

} catch (Exception e) {
throw new BuildException(e);
}
}
}
42 changes: 42 additions & 0 deletions src/main/java/net/wasdev/wlp/ant/servertasks/ServerPackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* (C) Copyright IBM Corporation 2014, 2015.
*
* 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 net.wasdev.wlp.ant.servertasks;

import java.util.List;

import org.apache.tools.ant.BuildException;

import net.wasdev.wlp.ant.ServerTask;

public class ServerPackage extends ServerTask {
@Override
public void execute() {
initTask();

try {
List<String> command = getInitialCommand("package");
addArchiveOption(command);
addIncludeOption(command);
addOsOption(command);
processBuilder.command(command);
Process p = processBuilder.start();
checkReturnCode(p, processBuilder.command().toString(), ReturnCode.OK.getValue());

} catch (Exception e) {
throw new BuildException(e);
}
}
}
66 changes: 66 additions & 0 deletions src/main/java/net/wasdev/wlp/ant/servertasks/ServerRun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* (C) Copyright IBM Corporation 2014, 2015.
*
* 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 net.wasdev.wlp.ant.servertasks;

import java.text.MessageFormat;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;

import net.wasdev.wlp.ant.ServerTask;

public class ServerRun extends ServerTask {
@Override
public void execute() {
initTask();

try {
// create server first if it doesn't exist
if (!serverConfigRoot.exists()) {
log(MessageFormat.format(messages.getString("info.server.create"), serverName));
doCreate();
}

List<String> command = getInitialCommand("run");
addCleanOption(command);
processBuilder.command(command);
final Process p = processBuilder.start();
final AtomicBoolean shutdown = new AtomicBoolean(false);
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
shutdown.set(true);
List<String> stopCommand = getInitialCommand("stop");
processBuilder.command(stopCommand);
try {
Process p = processBuilder.start();
p.waitFor();
} catch (Exception e) {
log("Error stopping server", e, Project.MSG_WARN);
}
}
});
int exitCode = getReturnCode(p, processBuilder.command().toString());
if (!shutdown.get() && exitCode != ReturnCode.OK.getValue()) {
throw new BuildException(MessageFormat.format(messages.getString("error.invoke.command"),
processBuilder.command().toString(), exitCode, ReturnCode.OK.getValue()));
}
} catch (Exception e) {
throw new BuildException(e);
}
}
}
55 changes: 55 additions & 0 deletions src/main/java/net/wasdev/wlp/ant/servertasks/ServerStart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* (C) Copyright IBM Corporation 2014, 2015.
*
* 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 net.wasdev.wlp.ant.servertasks;

import java.text.MessageFormat;
import java.util.List;

import org.apache.tools.ant.BuildException;

import net.wasdev.wlp.ant.ServerTask;

public class ServerStart extends ServerTask {
@Override
public void execute() {
initTask();

try {
// create server first if it doesn't exist
if (!serverConfigRoot.exists()) {
log(MessageFormat.format(messages.getString("info.server.create"), serverName));
doCreate();
}

List<String> command = getInitialCommand("start");
addCleanOption(command);
processBuilder.command(command);
Process p = processBuilder.start();
checkReturnCode(p, processBuilder.command().toString(), ReturnCode.OK.getValue(),
ReturnCode.REDUNDANT_ACTION_STATUS.getValue());

// check server started message code.
long startTimeout = SERVER_START_TIMEOUT_DEFAULT;
if (timeout != null && !timeout.equals("")) {
startTimeout = Long.valueOf(timeout);
}
validateServerStarted(getLogFile(), startTimeout);

} catch (Exception e) {
throw new BuildException(e);
}
}
}
45 changes: 45 additions & 0 deletions src/main/java/net/wasdev/wlp/ant/servertasks/ServerStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* (C) Copyright IBM Corporation 2014, 2015.
*
* 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 net.wasdev.wlp.ant.servertasks;

import java.util.List;

import org.apache.tools.ant.BuildException;

import net.wasdev.wlp.ant.ServerTask;

public class ServerStatus extends ServerTask {
@Override
public void execute() {
initTask();

try {
List<String> command = getInitialCommand("status");
processBuilder.command(command);
Process p = processBuilder.start();
int exitCode = getReturnCode(p, processBuilder.command().toString());

if (resultProperty == null) {
resultProperty = "wlp." + serverName + ".status";
}

getProject().setUserProperty(resultProperty, String.valueOf(exitCode));

} catch (Exception e) {
throw new BuildException(e);
}
}
}
Loading

0 comments on commit f0c1643

Please sign in to comment.