Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ class DevTask extends AbstractFeatureTask {
private static final double DEFAULT_COMPILE_WAIT = 0.5;
private static final int DEFAULT_DEBUG_PORT = 7777;
private static final boolean DEFAULT_HOT_TESTS = false;
private static final boolean DEFAULT_SKIP_TESTS = false;
private static final boolean DEFAULT_SKIP_TESTS = false;
private static final boolean DEFAULT_LIBERTY_DEBUG = true;
private static final boolean DEFAULT_POLLING_TEST = false;
private static final boolean DEFAULT_CONTAINER = false;
private static final boolean DEFAULT_SKIP_DEFAULT_PORTS = false;
private static final boolean DEFAULT_KEEP_TEMP_CONTAINERFILE = false;
private static final boolean DEFAULT_GENERATE_FEATURES = false;
private static final boolean DEFAULT_GENERATE_FEATURES = true;
private static final boolean DEFAULT_GENERATE_TO_SRC = false;
private static final boolean DEFAULT_SKIP_INSTALL_FEATURE = false;
private static final boolean DEFAULT_CHANGE_ON_DEMAND_TESTS_ACTION = false;

Expand Down Expand Up @@ -335,6 +336,16 @@ class DevTask extends AbstractFeatureTask {
this.generateFeatures = Boolean.parseBoolean(generateFeatures);
}

@Optional
@Input
Boolean generateToSrc = null;

// Need to use a string value to allow the ability to specify a value for the parameter (ie. --generateToSrc=false)
@Option(option = 'generateToSrc', description = 'Generate features to a file in the project\'s src directory')
void setGenerateToSrc(String generateToSrc) {
this.generateToSrc = Boolean.parseBoolean(generateToSrc);
}

@Optional
@Input
Boolean skipInstallFeature;
Expand Down Expand Up @@ -379,15 +390,16 @@ class DevTask extends AbstractFeatureTask {
int verifyAppStartTimeout, int appUpdateTimeout, double compileWait,
boolean libertyDebug, boolean pollingTest, boolean container, File containerfile, File containerBuildContext,
String containerRunOpts, int containerBuildTimeout, boolean skipDefaultPorts, boolean keepTempContainerfile,
String mavenCacheLocation, String packagingType, File buildFile, boolean generateFeatures, List<Path> webResourceDirs,
String mavenCacheLocation, String packagingType, File buildFile, boolean generateFeatures, boolean generateToSrc, List<Path> webResourceDirs,
List<ProjectModule> projectModuleList, Map<String, List<String>> parentBuildGradle, File serverOutputDir
) throws IOException, PluginExecutionException {
super(buildDir, serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, projectDirectory, /* multi module project directory */ projectDirectory,
resourceDirs, changeOnDemandTestsAction, hotTests, skipTests, false /* skipUTs */, false /* skipITs */, skipInstallFeature, artifactId, serverStartTimeout,
verifyAppStartTimeout, appUpdateTimeout, ((long) (compileWait * 1000L)), libertyDebug,
true /* useBuildRecompile */, true /* gradle */, pollingTest, container, containerfile, containerBuildContext, containerRunOpts, containerBuildTimeout, skipDefaultPorts,
null /* compileOptions not needed since useBuildRecompile is true */, keepTempContainerfile, mavenCacheLocation, projectModuleList /* multi module upstream projects */,
projectModuleList.size() > 0 /* recompileDependencies as true for multi module */, packagingType, buildFile, parentBuildGradle /* parent build files */, generateFeatures, null /* compileArtifactPaths */, null /* testArtifactPaths */, webResourceDirs /* webResources */
projectModuleList.size() > 0 /* recompileDependencies as true for multi module */, packagingType, buildFile, parentBuildGradle /* parent build files */,
generateFeatures, generateToSrc, null /* compileArtifactPaths */, null /* testArtifactPaths */, webResourceDirs /* webResources */
);
this.libertyDirPropertyFiles = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new CommonLogger(project), installDirectory, userDirectory, serverDirectory, serverOutputDir);
ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles);
Expand Down Expand Up @@ -1220,6 +1232,10 @@ class DevTask extends AbstractFeatureTask {
generateFeatures = DEFAULT_GENERATE_FEATURES;
}

if (generateToSrc == null) {
generateToSrc = DEFAULT_GENERATE_TO_SRC;
}

processDevExtensionParams();
}

Expand Down Expand Up @@ -1289,7 +1305,7 @@ class DevTask extends AbstractFeatureTask {
verifyAppStartTimeout.intValue(), verifyAppStartTimeout.intValue(), compileWait.doubleValue(),
libertyDebug.booleanValue(), pollingTest.booleanValue(), container.booleanValue(), containerfile, containerBuildContext, containerRunOpts,
containerBuildTimeout, skipDefaultPorts.booleanValue(), keepTempContainerfile.booleanValue(), localMavenRepoForFeatureUtility,
DevTaskHelper.getPackagingType(project), buildFile, generateFeatures.booleanValue(), webResourceDirs, projectModules, parentBuildGradle, new File(outputDir, serverName)
DevTaskHelper.getPackagingType(project), buildFile, generateFeatures.booleanValue(), generateToSrc.booleanValue(), webResourceDirs, projectModules, parentBuildGradle, new File(outputDir, serverName)
);
} catch (IOException | PluginExecutionException e) {
throw new GradleException("Error initializing dev mode.", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class GenerateFeaturesTask extends AbstractFeatureTask {
private static final boolean DEFAULT_OPTIMIZE = true;
// Default value of the generateToSrc option
private static final boolean DEFAULT_GENERATETOSRC = false;
// Default value of the internalDevMode option
private static final boolean DEFAULT_DEVMODE = false;

// The executable file used to scan binaries for the Liberty features they use.
private File binaryScanner;
Expand Down Expand Up @@ -90,6 +92,19 @@ class GenerateFeaturesTask extends AbstractFeatureTask {
this.generateToSrc = Boolean.parseBoolean(generateToSrc);
}

private Boolean internalDevMode = null;

/**
* The internalDevMode parameter is for internal use only. It is not for users.
* The parameter is only used when generateToSrc is false meaning we generate to serverDir.
* When the parameter is true we will write the generated features file to the temp directory.
* This is required because the features must all be installed before writing to server Dir in devmode.
*/
@Option(option = 'internalDevMode', description = 'Internal only option indicating dev mode is active')
void setInternalDevMode(String internalDevMode) {
this.internalDevMode = Boolean.parseBoolean(internalDevMode);
}

@TaskAction
void generateFeatures() {
binaryScanner = getBinaryScannerJarFromRepository();
Expand All @@ -101,6 +116,9 @@ class GenerateFeaturesTask extends AbstractFeatureTask {
if (generateToSrc == null) {
generateToSrc = DEFAULT_GENERATETOSRC;
}
if (internalDevMode == null) {
internalDevMode = DEFAULT_DEVMODE;
}

initializeConfigDirectory();
// The server.configDirectory is in the src directory. Otherwise generate for the build dir.
Expand Down Expand Up @@ -218,7 +236,14 @@ class GenerateFeaturesTask extends AbstractFeatureTask {
logger.debug("Features detected by binary scanner which are not in server.xml : " + missingLibertyFeatures);

// generate the new features into an xml file in the correct context directory
def generatedXmlFile = new File(generationContextDir, GENERATED_FEATURES_FILE_PATH);
def generatedXmlFile;
if (internalDevMode) {
// create a temp dir in the build directory for the generated-features.xml in dev mode
// The ServerConfigXmlDocument will create the directories if needed.
generatedXmlFile = new File(project.getLayout().getBuildDirectory().getAsFile().get(), GENERATED_FEATURES_TEMP_PATH);
} else {
generatedXmlFile = new File(generationContextDir, GENERATED_FEATURES_FILE_PATH);
}
try {
if (missingLibertyFeatures.size() > 0) {
Set<String> existingGeneratedFeatures = getGeneratedFeatures(servUtil, generatedXmlFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ class BaseGenerateFeaturesTest extends AbstractIntegrationTest {
static File serverXmlFile;
static File newFeatureFile;
static File newFeatureFileSrc;
static File newFeatureFileTmp;

static final String GENERATED_FEATURES_FILE_NAME = "generated-features.xml";
static final String GENERATED_FEATURES_FILE_PATH = "/build/wlp/usr/servers/defaultServer/configDropins/overrides/" + GENERATED_FEATURES_FILE_NAME;
static final String GENERATED_FEATURES_FILE_PATH_SRC = "/src/main/liberty/config/configDropins/overrides/" + GENERATED_FEATURES_FILE_NAME;
static final String GENERATED_FEATURES_FILE_PATH_TMP = "/build/.libertyFeatures/" + GENERATED_FEATURES_FILE_NAME;
static final String UMBRELLA_EE = "providedCompile \"jakarta.platform:jakarta.jakartaee-api:8.0.0\"";
static final String UMBRELLA_MP = "providedCompile \"org.eclipse.microprofile:microprofile:3.2\"";
static final String ESA_EE_DEPENDENCY = "providedCompile 'io.openliberty.features:servlet-4.0:22.0.0.2'";
Expand All @@ -64,6 +66,7 @@ class BaseGenerateFeaturesTest extends AbstractIntegrationTest {
static final String UMBRELLA_MP_OLD = "providedCompile 'org.eclipse.microprofile:microprofile:1.2'";
static final String TARGET_EE_NULL = "targetJavaEE: null";
static final String TARGET_MP_NULL = "targetMicroP: null";
static final String DEBUG_OPTION = "--debug";

protected static void setUpBeforeTest(String projectName) throws IOException, InterruptedException, FileNotFoundException {
this.projectName = projectName;
Expand All @@ -74,6 +77,7 @@ class BaseGenerateFeaturesTest extends AbstractIntegrationTest {
createTestProject(buildDir, resourceDir, buildFilename);
this.newFeatureFile = new File(buildDir, GENERATED_FEATURES_FILE_PATH);
this.newFeatureFileSrc = new File(buildDir, GENERATED_FEATURES_FILE_PATH_SRC);
this.newFeatureFileTmp = new File(buildDir, GENERATED_FEATURES_FILE_PATH_TMP);
this.buildFile = new File(buildDir, buildFilename);
serverXmlFile = new File(buildDir, "src/main/liberty/config/server.xml");
}
Expand Down Expand Up @@ -237,16 +241,12 @@ class BaseGenerateFeaturesTest extends AbstractIntegrationTest {
return features;
}

protected static void runCompileAndGenerateFeatures() throws IOException, InterruptedException, FileNotFoundException {
runProcess("compileJava generateFeatures");
}

protected static void runCompileAndGenerateFeaturesToSrc() throws IOException, InterruptedException, FileNotFoundException {
runProcess("compileJava generateFeatures --generateToSrc=true");
}

protected static void runCompileAndGenerateFeaturesDebug() throws IOException, InterruptedException, FileNotFoundException {
runProcess("compileJava generateFeatures --debug");
protected static void runCompileAndGenerateFeatures(String options) throws IOException, InterruptedException, FileNotFoundException {
String parameters = "compileJava generateFeatures ";
if (options != null) {
parameters += options;
}
runProcess(parameters);
}

protected static void runGenerateFeatures(String options) throws IOException, InterruptedException, FileNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {

@Test
public void basicTest() throws Exception {
runCompileAndGenerateFeatures();
runCompileAndGenerateFeatures(null);
executeBasicTests(newFeatureFile, "");
}

Expand Down Expand Up @@ -75,14 +75,26 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {

@Test
public void generateToSrcTest() throws Exception {
String options = "--generateToSrc=true";
newFeatureFile.delete(); // clean up from other tests but file may not be present so don't assert
assertFalse(newFeatureFileSrc.exists()); // assuming no other test creates this file
runCompileAndGenerateFeaturesToSrc();
runCompileAndGenerateFeatures(options);

executeBasicTests(newFeatureFileSrc, "--generateToSrc=true");
executeBasicTests(newFeatureFileSrc, options);
assertTrue(newFeatureFileSrc.delete()); // clean up the generated file
}

@Test
public void internalDevModeTest() throws Exception {
String options = "--internalDevMode=true";
newFeatureFile.delete(); // clean up from other tests but file may not be present so don't assert
assertFalse(newFeatureFileTmp.exists()); // assuming no other test creates this file
runCompileAndGenerateFeatures(options);

executeBasicTests(newFeatureFileTmp, options);
assertTrue(newFeatureFileTmp.delete()); // clean up the generated file
}

@Test
public void noClassFiles() throws Exception {
// do not compile before running generateFeatures
Expand All @@ -105,7 +117,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
File scannerLogDir = new File(targetDir, "logs");
assertFalse(scannerLogDir.exists());

runCompileAndGenerateFeaturesDebug();
runCompileAndGenerateFeatures(DEBUG_OPTION);
assertTrue(scannerLogDir.exists());
File[] logDirListing = scannerLogDir.listFiles();
assertNotNull(logDirListing);
Expand All @@ -128,7 +140,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
"</featureManager>\n", serverXmlFile);
assertFalse("Before running", newFeatureFile.exists());
// run the test
runCompileAndGenerateFeatures();
runCompileAndGenerateFeatures(null);

// verify that the generated features file was created
assertTrue(newFeatureFile.exists());
Expand All @@ -147,7 +159,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
// also we wish to test behaviour when there is no <featureManager> element so test that
assertFalse(verifyLogMessageExists("<featureManager>", 10, serverXmlFile));

runCompileAndGenerateFeatures();
runCompileAndGenerateFeatures(null);

// verify that generated features file was created
assertTrue(newFeatureFile.exists());
Expand All @@ -171,7 +183,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
// initially the expected comment is not found in server.xml
assertFalse(verifyLogMessageExists(GenerateFeaturesTask.FEATURES_FILE_MESSAGE, 10, serverXmlFile));

runCompileAndGenerateFeatures();
runCompileAndGenerateFeatures(null);

// verify that generated features file was created
assertTrue(newFeatureFile.exists());
Expand Down Expand Up @@ -199,7 +211,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
" <feature>servlet-4.0</feature>\n" +
" <feature>cdi-1.2</feature>\n" +
" </featureManager>\n", serverXmlFile);
runCompileAndGenerateFeatures();
runCompileAndGenerateFeatures(null);

// Verify BINARY_SCANNER_CONFLICT_MESSAGE2 error is thrown (BinaryScannerUtil.RecommendationSetException)
Set<String> recommendedFeatureSet = new HashSet<String>(Arrays.asList("servlet-4.0"));
Expand All @@ -222,7 +234,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
" <featureManager>\n" +
" <feature>cdi-1.2</feature>\n" +
" </featureManager>\n", serverXmlFile);
runCompileAndGenerateFeatures();
runCompileAndGenerateFeatures(null);

// Verify BINARY_SCANNER_CONFLICT_MESSAGE1 error is thrown (BinaryScannerUtil.FeatureModifiedException)
Set<String> recommendedFeatureSet = new HashSet<String>(Arrays.asList("cdi-2.0", "servlet-4.0"));
Expand Down Expand Up @@ -250,7 +262,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
" <featureManager>\n" +
" <feature>mpOpenAPI-1.0</feature>\n" +
" </featureManager>\n", serverXmlFile);
runCompileAndGenerateFeatures();
runCompileAndGenerateFeatures(null);

// use just beginning of BINARY_SCANNER_CONFLICT_MESSAGE5 as error message in logFile may be interrupted with "1 actionable task: 1 executed"
assertTrue("Could not find the feature unavailable conflict message in the process output.\n" + processOutput,
Expand All @@ -267,7 +279,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
*/
@Test
public void bothEEMPUmbrellaTest() throws Exception {
runCompileAndGenerateFeaturesDebug();
runCompileAndGenerateFeatures(DEBUG_OPTION);
// Check for " targetJavaEE: null" in the debug output
String line = findLogMessage(TARGET_EE_NULL, 5000, logFile);
assertNull("Target EE:'" + line+"'", line);
Expand All @@ -286,7 +298,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
public void onlyEEUmbrellaTest() throws Exception {
replaceString(UMBRELLA_MP, ESA_MP_DEPENDENCY, buildFile);
removeUnusedUmbrellas(buildFile);
runCompileAndGenerateFeaturesDebug();
runCompileAndGenerateFeatures(DEBUG_OPTION);
// Check for " targetJavaEE: null" in the debug output
String line = findLogMessage(TARGET_EE_NULL, 5000, logFile);
assertNull("Target EE:" + line, line);
Expand All @@ -305,7 +317,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
public void onlyMPUmbrellaTest() throws Exception {
replaceString(UMBRELLA_EE, ESA_EE_DEPENDENCY, buildFile);
removeUnusedUmbrellas(buildFile);
runCompileAndGenerateFeaturesDebug();
runCompileAndGenerateFeatures(DEBUG_OPTION);
// Check for " targetJavaEE: null" in the debug output
String line = findLogMessage(TARGET_EE_NULL, 5000, logFile);
assertNotNull("Target EE:" + line, line);
Expand All @@ -325,7 +337,7 @@ class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
replaceString(UMBRELLA_EE, ESA_EE_DEPENDENCY, buildFile);
replaceString(UMBRELLA_MP, ESA_MP_DEPENDENCY, buildFile);
removeUnusedUmbrellas(buildFile);
runCompileAndGenerateFeaturesDebug();
runCompileAndGenerateFeatures(DEBUG_OPTION);
// Check for " targetJavaEE: null" in the debug output
String line = findLogMessage(TARGET_EE_NULL, 5000, logFile);
assertNotNull("Target EE:" + line, line);
Expand Down