public abstract class DevUtil extends AbstractContainerSupportUtil
| Modifier and Type | Class and Description |
|---|---|
class |
DevUtil.TestJob |
| Modifier and Type | Field and Description |
|---|---|
protected List<String> |
destMount |
static String |
DEVC_HIDDEN_FOLDER |
static String |
DEVMODE_PROJECT_ROOT |
protected AtomicBoolean |
hasFeaturesSh |
protected AtomicBoolean |
serverFullyStarted |
static String |
SKIP_BETA_INSTALL_WARNING |
protected List<String> |
srcMount |
| Constructor and Description |
|---|
DevUtil(File buildDirectory,
File serverDirectory,
File sourceDirectory,
File testSourceDirectory,
File configDirectory,
File projectDirectory,
List<File> resourceDirs,
boolean hotTests,
boolean skipTests,
boolean skipUTs,
boolean skipITs,
String applicationId,
long serverStartTimeout,
int appStartupTimeout,
int appUpdateTimeout,
long compileWaitMillis,
boolean libertyDebug,
boolean useBuildRecompile,
boolean gradle,
boolean pollingTest,
boolean container,
File dockerfile,
String dockerRunOpts,
int dockerBuildTimeout,
boolean skipDefaultPorts,
JavaCompilerOptions compilerOptions,
boolean keepTempDockerfile,
String mavenCacheLocation) |
| Modifier and Type | Method and Description |
|---|---|
void |
addShutdownHook(ThreadPoolExecutor executor) |
abstract void |
checkConfigFile(File configFile,
File serverDir)
Check the configuration file for new features
|
protected void |
cleanTargetDir(File outputDirectory)
Delete all the Java class files within the specified directory.
|
void |
cleanUpServerEnv() |
void |
cleanUpTempConfig() |
void |
cleanUpTempDockerfile() |
abstract boolean |
compile(File dir)
Compile the specified directory
|
void |
copyConfigFolder(File fileChanged,
File srcDir,
String targetFileName)
Creates a temporary copy of the configuration file and checks the configFile
in the temporary directory to avoid install-feature timing issues
|
void |
copyFile(File fileChanged,
File srcDir,
File targetDir,
String targetFileName)
Copies the fileChanged from the srcDir to the targetDir.
|
int |
countApplicationUpdatedMessages()
Get the number of times the application updated message has appeared in the
application log
|
abstract void |
debug(String msg)
Log debug
|
abstract void |
debug(String msg,
Throwable e)
Log debug
|
abstract void |
debug(Throwable e)
Log debug
|
protected void |
deleteFile(File deletedFile,
File dir,
File targetDir,
String targetFileName)
Deletes the corresponding file in the targetDir.
|
protected void |
deleteJavaFile(File fileChanged,
File classesDir,
File compileSourceRoot)
Given the fileChanged delete the corresponding Java class or directory
|
protected void |
detectFeaturesSh(List<String> dockerfileLines) |
protected void |
disableOpenJ9SCC(List<String> dockerfileLines)
Disables OpenJ9 SCC to speed up build times by injecting environment variable before "RUN configure.sh" is called.
|
void |
enableServerDebug()
Enable server debug variables in server.env, using the user specified debug
port if it's available, otherwise uses a random available port.
|
abstract void |
error(String msg)
Log error
|
abstract void |
error(String msg,
Throwable e)
Log error
|
int |
findAvailablePort(int preferredPort,
boolean isDebugPort)
Finds an available port to use.
|
abstract List<String> |
getArtifacts()
Updates artifacts of current project
|
protected Set<File> |
getClassPath(List<String> artifactPaths,
List<File> outputDirs)
Gets the class path for the specified artifactPaths and outputDirs.
|
protected static List<String> |
getCleanedLines(List<String> dockerfileLines)
Trim all lines and get them without comments or empty lines after the first FROM command
(so that directives at the beginning of the file are preserved)
|
protected static List<String> |
getCombinedLines(List<String> dockerfileLines,
char escape)
Combine multi-line commands into single lines.
|
String |
getContainerName() |
Map<String,String> |
getDebugEnvironmentVariables()
Gets a map of the environment variables to set for debug mode.
|
protected static char |
getEscapeCharacter(List<String> dockerfileLines)
Get escape character from the escape directive at the top of the Dockerfile.
|
protected File |
getFileFromConfigDirectory(String file)
Get the file from the configDirectory if it exists
|
String |
getHostName()
Gets the Liberty server's host name.
|
String |
getHttpPort()
Gets the Liberty server's http port.
|
String |
getHttpsPort()
Gets the Liberty server's https port.
|
abstract String |
getProjectName()
Get the name of the current project running dev mode.
|
abstract String |
getServerStartTimeoutExample()
Get an example command using the server start timeout parameter.
|
abstract io.openliberty.tools.ant.ServerTask |
getServerTask()
Get the ServerTask to start the server, which can be in either "run" or
"debug" mode
|
abstract void |
info(String msg)
Log info
|
abstract boolean |
isDebugEnabled()
Returns whether debug is enabled by the current logger
|
protected boolean |
isGeneratedConfigFile(File fileChanged,
File srcDir,
File targetDir)
Determines if the corresponding target config file was generated by a Liberty
plugin
|
abstract boolean |
isLooseApplication()
Is the application deployed as a loose application.
|
abstract void |
libertyCreate() |
abstract void |
libertyDeploy() |
abstract void |
libertyInstallFeature()
Install features in regular dev mode.
|
protected int |
parseHostName(String webAppMessage) |
protected void |
parseHttpPort(String webAppMessage,
int portPrefixIndex) |
protected void |
parseHttpsPort(List<String> messages) |
protected static String[] |
parseNetworks(String dockerResult)
Parses Docker network names from a "docker inspect" command result on a container.
|
protected File |
prepareTempDockerfile(File dockerfile) |
protected void |
processCopyLines(List<String> dockerfileLines,
String buildContext) |
protected List<String> |
readDockerfile(File dockerfile) |
String |
readFile(File file)
Reads the file to a String
|
abstract boolean |
recompileBuildFile(File buildFile,
List<String> artifactPaths,
ThreadPoolExecutor executor)
Recompile the build file
|
protected boolean |
recompileJava(Collection<File> javaFilesChanged,
List<String> artifactPaths,
ThreadPoolExecutor executor,
boolean tests,
File outputDirectory,
File testOutputDirectory)
Recompile source files
|
protected boolean |
recompileJavaSource(Collection<File> javaFilesChanged,
List<String> artifactPaths,
ThreadPoolExecutor executor,
File outputDirectory,
File testOutputDirectory)
Recompile Java source files and run tests after application update
|
protected boolean |
recompileJavaTest(Collection<File> javaFilesChanged,
List<String> artifactPaths,
ThreadPoolExecutor executor,
File outputDirectory,
File testOutputDirectory)
Recompile test source files and run tests immediately
|
abstract void |
redeployApp()
Redeploy the application
|
protected void |
registerAll(Path start,
ThreadPoolExecutor executor)
Register the parent directory and all sub-directories with the WatchService
|
protected void |
registerAll(Path start,
ThreadPoolExecutor executor,
boolean removeOnContainerRebuild)
Register the parent directory and all sub-directories with the WatchService
|
protected static String |
removeSurroundingQuotes(String str) |
protected void |
removeWarFileLines(List<String> dockerfileLines) |
void |
restartServer() |
void |
restartServer(boolean buildContainer)
Stop the server, set up Liberty and restart it.
|
void |
runHotkeyReaderThread(ThreadPoolExecutor executor)
Run a hotkey reader thread.
|
abstract void |
runIntegrationTests()
Run the integration tests
|
void |
runTests(boolean waitForApplicationUpdate,
int messageOccurrences,
ThreadPoolExecutor executor,
boolean forceSkipUTs)
Run unit and/or integration tests
|
void |
runTestThread(boolean waitForApplicationUpdate,
ThreadPoolExecutor executor,
int messageOccurrences,
boolean forceSkipUTs,
boolean manualInvocation)
Run tests in a new thread.
|
abstract void |
runUnitTests()
Run the unit tests
|
void |
setDevStop(boolean devStop)
Whether dev mode intentionally caused the server to stop.
|
void |
setLibertyDebugPort(int libertyDebugPort)
Sets the preferred debug port.
|
void |
setPropertyFiles(List<File> propertyFiles)
This is needed for Gradle only.
|
void |
startServer() |
void |
startServer(boolean buildContainer,
boolean pullParentImage)
Start the server and keep it running in a background thread.
|
abstract void |
stopServer()
Stop the server
|
abstract void |
warn(String msg)
Log warning
|
void |
watchFiles(File buildFile,
File outputDirectory,
File testOutputDirectory,
ThreadPoolExecutor executor,
List<String> artifactPaths,
File serverXmlFile,
File bootstrapPropertiesFile,
File jvmOptionsFile) |
execDockerCmd, readStdOutpublic static final String DEVMODE_PROJECT_ROOT
public static final String SKIP_BETA_INSTALL_WARNING
public static final String DEVC_HIDDEN_FOLDER
protected AtomicBoolean hasFeaturesSh
protected AtomicBoolean serverFullyStarted
public DevUtil(File buildDirectory, File serverDirectory, File sourceDirectory, File testSourceDirectory, File configDirectory, File projectDirectory, List<File> resourceDirs, boolean hotTests, boolean skipTests, boolean skipUTs, boolean skipITs, String applicationId, long serverStartTimeout, int appStartupTimeout, int appUpdateTimeout, long compileWaitMillis, boolean libertyDebug, boolean useBuildRecompile, boolean gradle, boolean pollingTest, boolean container, File dockerfile, String dockerRunOpts, int dockerBuildTimeout, boolean skipDefaultPorts, JavaCompilerOptions compilerOptions, boolean keepTempDockerfile, String mavenCacheLocation)
public abstract void debug(String msg)
debug in class AbstractContainerSupportUtilmsg - public abstract void debug(Throwable e)
e - public abstract void warn(String msg)
msg - public abstract void info(String msg)
msg - public abstract void error(String msg)
msg - public abstract void error(String msg, Throwable e)
error in class AbstractContainerSupportUtilmsg - e - public abstract boolean isDebugEnabled()
public abstract boolean recompileBuildFile(File buildFile, List<String> artifactPaths, ThreadPoolExecutor executor) throws PluginExecutionException
buildFile - artifactPaths - executor - The thread pool executorPluginExecutionException - if there was an error when restarting the
serverpublic abstract void runUnitTests()
throws PluginScenarioException,
PluginExecutionException
PluginScenarioException - if unit tests failedPluginExecutionException - if unit tests could not be runpublic abstract void runIntegrationTests()
throws PluginScenarioException,
PluginExecutionException
PluginScenarioException - if integration tests failedPluginExecutionException - if integration tests could not be runpublic abstract void checkConfigFile(File configFile, File serverDir)
configFile - serverDir - public abstract boolean compile(File dir)
dir - public abstract void stopServer()
public abstract io.openliberty.tools.ant.ServerTask getServerTask()
throws Exception
Exception - if there was an error copying/creating config filespublic abstract void redeployApp()
throws PluginExecutionException
PluginExecutionExceptionpublic abstract String getServerStartTimeoutExample()
public abstract String getProjectName()
public abstract boolean isLooseApplication()
public void runTests(boolean waitForApplicationUpdate,
int messageOccurrences,
ThreadPoolExecutor executor,
boolean forceSkipUTs)
waitForApplicationUpdate - Whether to wait for the application to update
before running integration testsmessageOccurrences - The previous number of times the application
updated message has appeared.executor - The thread pool executorforceSkipUTs - Whether to force skip the unit testspublic int countApplicationUpdatedMessages()
public void startServer()
throws PluginExecutionException
PluginExecutionExceptionpublic void startServer(boolean buildContainer,
boolean pullParentImage)
throws PluginExecutionException
buildContainer - Force a Docker build when in container mode. Ignored
otherwise.pullParentImage - If buildContainer is true, this determines whether the
Docker build should also pull the latest parent image.
Ignored otherwise.PluginExecutionException - If the server startup could not be verified
within the timeout, or server startup
failed.protected List<String> readDockerfile(File dockerfile) throws PluginExecutionException
PluginExecutionExceptionprotected static char getEscapeCharacter(List<String> dockerfileLines) throws PluginExecutionException
PluginExecutionExceptionprotected static List<String> getCleanedLines(List<String> dockerfileLines) throws PluginExecutionException
PluginExecutionExceptionprotected static List<String> getCombinedLines(List<String> dockerfileLines, char escape) throws PluginExecutionException
PluginExecutionExceptionprotected void removeWarFileLines(List<String> dockerfileLines) throws PluginExecutionException
PluginExecutionExceptionprotected void disableOpenJ9SCC(List<String> dockerfileLines)
protected void processCopyLines(List<String> dockerfileLines, String buildContext) throws PluginExecutionException
PluginExecutionExceptionprotected File prepareTempDockerfile(File dockerfile) throws PluginExecutionException
PluginExecutionExceptionprotected static String[] parseNetworks(String dockerResult)
dockerResult - the result from the command "docker inspect -f '{{.NetworkSettings.Networks}}' containerName"
-> dockerResult must not contain surrounding quotes or leading/trailing whitespacepublic abstract void libertyCreate()
throws PluginExecutionException
PluginExecutionExceptionpublic abstract void libertyDeploy()
throws PluginExecutionException
PluginExecutionExceptionpublic abstract void libertyInstallFeature()
throws PluginExecutionException
PluginExecutionExceptionpublic void restartServer()
throws PluginExecutionException
PluginExecutionExceptionpublic void restartServer(boolean buildContainer)
throws PluginExecutionException
buildContainer - Force a Docker build when in container mode. Ignored otherwise.PluginExecutionExceptionprotected int parseHostName(String webAppMessage) throws PluginExecutionException
PluginExecutionExceptionprotected void parseHttpPort(String webAppMessage, int portPrefixIndex)
protected void parseHttpsPort(List<String> messages) throws PluginExecutionException
PluginExecutionExceptionpublic void cleanUpServerEnv()
public void cleanUpTempConfig()
public void cleanUpTempDockerfile()
public void setDevStop(boolean devStop)
devStop - If true, stopping the server will not cause dev mode to print
an error message.public void addShutdownHook(ThreadPoolExecutor executor)
public Map<String,String> getDebugEnvironmentVariables() throws IOException
libertyDebugPort - the debug port to useIOExceptionpublic void enableServerDebug()
throws IOException
IOException - if there was an IO exception when reading or writing the
server.envpublic int findAvailablePort(int preferredPort,
boolean isDebugPort)
throws IOException
The - number of the port to start the search for an available port.Whether - to choose an ephemeral port. True to choose an ephemeral port,
false to search sequentially.IOException - if it could not find any available port, or there was an
error when opening a server socket regardless of port.public void runHotkeyReaderThread(ThreadPoolExecutor executor)
executor - the test thread executorpublic void watchFiles(File buildFile, File outputDirectory, File testOutputDirectory, ThreadPoolExecutor executor, List<String> artifactPaths, File serverXmlFile, File bootstrapPropertiesFile, File jvmOptionsFile) throws Exception
Exceptionprotected boolean isGeneratedConfigFile(File fileChanged, File srcDir, File targetDir) throws IOException
fileChanged - the file that was changedsrcDir - the directory of the file changedtargetDir - the target directoryIOException - unable to resolve canonical pathpublic String readFile(File file) throws IOException
file - IOException - unable to read file to stringpublic void copyConfigFolder(File fileChanged, File srcDir, String targetFileName) throws IOException
fileChanged - the file that was changedsrcDir - the directory of the file changedtargetFileName - if not null renames the fileChanged to targetFileName
in the targetDirIOException - creating and copying to tempConfig directorypublic void copyFile(File fileChanged, File srcDir, File targetDir, String targetFileName) throws IOException
fileChanged - the file that was changedsrcDir - the directory of the file changedtargetDir - the target directorytargetFileName - if not null renames the fileChanged to targetFileName
in the targetDirIOException - unable to resolve canonical pathprotected void deleteFile(File deletedFile, File dir, File targetDir, String targetFileName) throws IOException
deletedFile - the file that was deleteddir - the directory of the deletedFiletargetDir - the corresponding targetDir of the deletedFiletargetFileName - if not null deletes the targetFile with this nameIOException - unable to resolve canonical pathprotected void cleanTargetDir(File outputDirectory)
outputDirectory - the directory for compiled classesprotected void registerAll(Path start, ThreadPoolExecutor executor) throws IOException
start - parent directoryexecutor - the test thread executorIOException - unable to walk through file treeprotected void registerAll(Path start, ThreadPoolExecutor executor, boolean removeOnContainerRebuild) throws IOException
start - parent directoryexecutor - the test thread executorremoveOnContainerRebuild - whether the files should be unwatched if the container is rebuiltIOException - unable to walk through file treeprotected File getFileFromConfigDirectory(String file)
file - protected void deleteJavaFile(File fileChanged, File classesDir, File compileSourceRoot) throws IOException
fileChanged - Java file changedclassesDir - the directory for compiled classescompileSourceRoot - the source directory for the Java classesIOException - unable to resolve canonical pathprotected boolean recompileJavaSource(Collection<File> javaFilesChanged, List<String> artifactPaths, ThreadPoolExecutor executor, File outputDirectory, File testOutputDirectory) throws PluginExecutionException
javaFilesChanged - collection of Java files changedartifactPaths - list of project artifact paths for building the classpathexecutor - the test thread executoroutputDirectory - the directory for compiled classestestOutputDirectory - the directory for compiled test classesPluginExecutionException - if the classes output directory doesn't exist and can't be createdprotected boolean recompileJavaTest(Collection<File> javaFilesChanged, List<String> artifactPaths, ThreadPoolExecutor executor, File outputDirectory, File testOutputDirectory) throws PluginExecutionException
javaFilesChanged - collection of Java files changedartifactPaths - list of project artifact paths for building the classpathexecutor - the test thread executoroutputDirectory - the directory for compiled classestestOutputDirectory - the directory for compiled test classesPluginExecutionException - if the classes output directory doesn't exist and can't be createdprotected boolean recompileJava(Collection<File> javaFilesChanged, List<String> artifactPaths, ThreadPoolExecutor executor, boolean tests, File outputDirectory, File testOutputDirectory) throws PluginExecutionException
javaFilesChanged - collection of Java files changedartifactPaths - list of project artifact paths for building the classpathexecutor - the test thread executortests - indicates whether the files changed were test filesoutputDirectory - the directory for compiled classestestOutputDirectory - the directory for compiled test classesPluginExecutionException - if the classes output directory doesn't exist and can't be createdprotected Set<File> getClassPath(List<String> artifactPaths, List<File> outputDirs) throws IOException
artifactPaths - list of artifacts for the current projectoutputDirs - list of output directories for the current projectIOException - unable to resolve canonical pathpublic void runTestThread(boolean waitForApplicationUpdate,
ThreadPoolExecutor executor,
int messageOccurrences,
boolean forceSkipUTs,
boolean manualInvocation)
waitForApplicationUpdate - whether it should wait for the application to
update before running integration testsexecutor - the thread pool executormessageOccurrences - how many times the application updated
message has occurred in the logforceSkipUTs - whether to force skip the unit testsmanualInvocation - whether the tests were manually invokedpublic String getHostName()
public String getHttpPort()
public String getHttpsPort()
public void setLibertyDebugPort(int libertyDebugPort)
libertyDebugPort - the preferred debug portpublic void setPropertyFiles(List<File> propertyFiles)
propertyFiles - list of property filespublic String getContainerName()
Copyright © 2021 the original author or authors.