Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support stripVersion for libertyApp configuration #630

Merged
merged 1 commit into from
Oct 11, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import org.apache.commons.io.FileUtils
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.tasks.bundling.War
import org.gradle.api.tasks.Internal
import org.gradle.plugins.ear.Ear
Expand Down Expand Up @@ -982,12 +984,24 @@ abstract class AbstractServerTask extends AbstractLibertyTask {
protected List<File> getApplicationFilesFromConfiguration() {
List<File> appFiles = new ArrayList<File>()

//This loops all the Dependency objects that get created by the configuration treating them as File objects
//Should also include transitive dependencies
//Can't use the resolved configuration unless we do a check separate from this one, not sure if there is an advantage since we want the applicaitons
project.configurations.libertyApp.each {
if (FilenameUtils.getExtension(it.name).equals('war') || FilenameUtils.getExtension(it.name).equals('ear')) {
appFiles.add(it)
//This loops thorugh all the Dependency objects that get created by the configuration
for (Dependency dep : project.configurations.libertyApp.getDependencies()) {
if (dep instanceof ModuleDependency) { //Check that dep isn't a File dependency
dep.setTransitive(false) //Only want main artifacts, one for Maven and one or more for Gradle/Ivy dependencies
}

Set<File> depArtifacts = project.configurations.libertyApp.files(dep) //Resolve the artifacts
for (File depArtifact : depArtifacts) {
File appFile = depArtifact
if (dep instanceof ModuleDependency && server.stripVersion && depArtifact.getName().contains(dep.getVersion())) {
String noVersionName = depArtifact.getName().minus("-" + dep.getVersion()) //Assuming default Gradle naming scheme
File noVersionDependencyFile = new File(project.getBuildDir(), 'libs/' + noVersionName) //Copying the file to build/libs with no version
FileUtils.copyFile(depArtifact, noVersionDependencyFile)
appFile = noVersionDependencyFile
}
if (FilenameUtils.getExtension(appFile.getName()).equals('war') || FilenameUtils.getExtension(appFile.getName()).equals('ear')) {
appFiles.add(appFile)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,14 @@ class DevTask extends AbstractServerTask {
boolean hotTests, boolean skipTests, String artifactId, int serverStartTimeout,
int verifyAppStartTimeout, int appUpdateTimeout, double compileWait,
boolean libertyDebug, boolean pollingTest, boolean container, File dockerfile, File dockerBuildContext,
String dockerRunOpts, int dockerBuildTimeout, boolean skipDefaultPorts, boolean keepTempDockerfile, String mavenCacheLocation, File buildFile
String dockerRunOpts, int dockerBuildTimeout, boolean skipDefaultPorts, boolean keepTempDockerfile, String mavenCacheLocation, String packagingType, File buildFile
) throws IOException {
super(buildDir, serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, projectDirectory, /* multi module project directory */ projectDirectory,
resourceDirs, hotTests, skipTests, false /* skipUTs */, false /* skipITs */, artifactId, serverStartTimeout,
verifyAppStartTimeout, appUpdateTimeout, ((long) (compileWait * 1000L)), libertyDebug,
true /* useBuildRecompile */, true /* gradle */, pollingTest, container, dockerfile, dockerBuildContext, dockerRunOpts, dockerBuildTimeout, skipDefaultPorts,
null /* compileOptions not needed since useBuildRecompile is true */, keepTempDockerfile, mavenCacheLocation, null /* multi module upstream projects */,
false /* recompileDependencies only supported in ci.maven */, getPackagingType(), buildFile, null /* parent build files */
false /* recompileDependencies only supported in ci.maven */, packagingType, buildFile, null /* parent build files */
);

ServerFeature servUtil = getServerFeatureUtil();
Expand Down Expand Up @@ -946,7 +946,7 @@ class DevTask extends AbstractServerTask {
resourceDirs, hotTests.booleanValue(), skipTests.booleanValue(), artifactId, serverStartTimeout.intValue(),
verifyAppStartTimeout.intValue(), verifyAppStartTimeout.intValue(), compileWait.doubleValue(),
libertyDebug.booleanValue(), pollingTest.booleanValue(), container.booleanValue(), dockerfile, dockerBuildContext, dockerRunOpts,
dockerBuildTimeout, skipDefaultPorts.booleanValue(), keepTempDockerfile.booleanValue(), localMavenRepoForFeatureUtility, buildFile
dockerBuildTimeout, skipDefaultPorts.booleanValue(), keepTempDockerfile.booleanValue(), localMavenRepoForFeatureUtility, getPackagingType(), buildFile
);

util.addShutdownHook(executor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LibertyApplicationConfigurationM2DefaultTest extends AbstractIntegrationTe

@Test
public void checkAppInstalled() {
assert new File(buildDir, 'build/wlp/usr/servers/defaultServer/apps/test-maven-war-1.0-SNAPSHOT.war').exists()
assert new File(buildDir, 'build/wlp/usr/servers/defaultServer/apps/test-maven-war.war').exists()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {

liberty {
server {
stripVersion = true
bootstrapProperties = ['default.http.port': 9080,
'default.https.port': 9443,
'appContext': 'servlet']
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
APP_LOCATION=test-maven-war-1.0-SNAPSHOT.war
APP_LOCATION=test-maven-war.war