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

LPD-15495 #2579

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ message.

<touch file="${liferay.home}/.liferay-home" />

<mkdir dir="${liferay.home}/deploy" />

<ant dir="sql" inheritAll="false" target="build-db" />

<deploy-properties />
Expand Down
6 changes: 1 addition & 5 deletions modules/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ The logic that chooses the default deploy directory is as follows:
1. Otherwise, the module is deployed to `${liferay home}/osgi/portal`.
- For themes:

1. If the `required-for-startup` property in the
`src/WEB-INF/liferay-plugin-package.properties` file is `true`, the theme is
deployed to `${liferay home}/osgi/war`.

1. Otherwise, the theme is deployed to `${liferay home}/deploy`.
1. The theme is deployed to `${liferay home}/osgi/portal-war`.

If possible, you should always use these marker files to specify the deploy
directory of your modules. If none of these cases apply to you, then add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ protected void activate(BundleContext bundleContext) throws Exception {
_getRequiredForStartupContextPaths(
Paths.get(PropsValues.LIFERAY_HOME, "osgi/war"));

requiredForStartupContextPaths.addAll(
_getRequiredForStartupContextPaths(
Paths.get(
PropsValues.LIFERAY_HOME, "osgi/portal-war")));

if (requiredForStartupContextPaths.isEmpty()) {
return null;
}
Expand Down
9 changes: 2 additions & 7 deletions modules/build-app-module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,7 @@
</condition>

<property name="artifact.location.dest" value="${output.dir}/${lpkg.title.prefix}${liferay.releng.app.title} - Impl/${artifact.name}-${artifact.version}.war" />

<condition property="artifact.location.src" value="${osgi.dir}/war/${artifact.name}.war">
<available file="${osgi.dir}/war/${artifact.name}.war" />
</condition>

<property name="artifact.location.src" value="${osgi.dir}/../deploy/${artifact.name}.war" />
<property name="artifact.location.src" value="${osgi.dir}/portal-war/${artifact.name}.war" />
</target>

<target depends="get-artifact-version-from-releng" if="artifact.legacy" name="get-artifact-properties-legacy">
Expand All @@ -352,7 +347,7 @@
</condition>

<property name="artifact.location.dest" value="${output.dir}/${lpkg.title.prefix}${liferay.releng.app.title} - Impl/${artifact.name}-${artifact.version}.war" />
<property name="artifact.location.src" value="${osgi.dir}/../deploy/${artifact.name}-${artifact.version}.war" />
<property name="artifact.location.src" value="${osgi.dir}/portal-war/${artifact.name}-${artifact.version}.war" />
</target>

<target name="get-artifact-properties-releng" unless="artifact.exclude">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.io.File;

import java.util.Properties;
import java.util.concurrent.Callable;

import org.gradle.api.Action;
Expand All @@ -47,7 +46,6 @@
import org.gradle.api.tasks.Copy;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.bundling.Zip;
import org.gradle.util.GUtil;

/**
* @author Andrea Di Giorgi
Expand Down Expand Up @@ -372,33 +370,16 @@ private void _configureDeployDir(Project project) {
final LiferayExtension liferayExtension = GradleUtil.getExtension(
project, LiferayExtension.class);

boolean requiredForStartup = _getPluginPackageProperty(
project, "required-for-startup");
liferayExtension.setDeployDir(
new Callable<File>() {

if (requiredForStartup) {
liferayExtension.setDeployDir(
new Callable<File>() {

@Override
public File call() throws Exception {
return new File(
liferayExtension.getLiferayHome(), "osgi/war");
}

});
}
else {
liferayExtension.setDeployDir(
new Callable<File>() {

@Override
public File call() throws Exception {
return new File(
liferayExtension.getLiferayHome(), "deploy");
}
@Override
public File call() throws Exception {
return new File(
liferayExtension.getLiferayHome(), "osgi/portal-war");
}

});
}
});
}

private void _configureExtensionPublishing(final Project project) {
Expand Down Expand Up @@ -542,19 +523,6 @@ public void execute(PackageRunBuildTask packageRunBuildTask) {
});
}

private boolean _getPluginPackageProperty(Project project, String key) {
File file = project.file(
"src/WEB-INF/liferay-plugin-package.properties");

if (!file.exists()) {
return false;
}

Properties properties = GUtil.loadProperties(file);

return Boolean.parseBoolean(properties.getProperty(key));
}

private Project _getThemeProject(Project project, String name) {
Project parentProject = project.getParent();

Expand Down
3 changes: 3 additions & 0 deletions modules/test/war-deploy-directory-test/bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bundle-Name: Liferay War Deploy Directory Test
Bundle-SymbolicName: com.liferay.war.deploy.directory.test
Bundle-Version: 1.0.0
3 changes: 3 additions & 0 deletions modules/test/war-deploy-directory-test/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
testIntegrationImplementation project(":test:arquillian-extension-junit-bridge")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/**
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/

package com.liferay.war.deploy.directory.test;

import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;

import java.io.File;

import java.nio.file.Files;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.FrameworkUtil;
import org.osgi.util.tracker.BundleTracker;

/**
* @author Dante Wang
*/
@RunWith(Arquillian.class)
public class WarDeployDirectoryTest {

@Test
public void testAutoDeployDir() {
File deployDir = new File(
PropsUtil.get(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR));

Assert.assertTrue(deployDir.exists());
Assert.assertTrue(deployDir.isDirectory());

File[] deployDirFiles = deployDir.listFiles();

Assert.assertEquals(
deployDirFiles.toString(), 0, deployDirFiles.length);
}

@Test
public void testPortalWarDir() {
Bundle currentBundle = FrameworkUtil.getBundle(
WarDeployDirectoryTest.class);

BundleContext bundleContext = currentBundle.getBundleContext();

List<String> installedWars = new ArrayList<>();

for (Bundle bundle : bundleContext.getBundles()) {
String location = bundle.getLocation();

if (location.startsWith("webbundle:")) {
installedWars.add(
location.substring(
10, location.indexOf(StringPool.QUESTION)));
}
}

File portalWarDir = new File(
PropsUtil.get("module.framework.portal.war.dir"));

Assert.assertTrue(portalWarDir.exists());
Assert.assertTrue(portalWarDir.isDirectory());

for (File file : portalWarDir.listFiles()) {
Assert.assertTrue(installedWars.remove(file.getAbsolutePath()));
}

Assert.assertTrue(installedWars.isEmpty());
}

@Test
public void testWarDir() throws Exception {
Bundle currentBundle = FrameworkUtil.getBundle(
WarDeployDirectoryTest.class);

BundleContext bundleContext = currentBundle.getBundleContext();

CountDownLatch addingBundleCountDownLatch = new CountDownLatch(1);
CountDownLatch removeBundleCountDownLatch = new CountDownLatch(1);

String testWarFileName = "test-war-dir.war";

BundleTracker<Bundle> bundleTracker = new BundleTracker<Bundle>(
bundleContext, Bundle.ACTIVE, null) {

@Override
public Bundle addingBundle(Bundle bundle, BundleEvent event) {
String bundleLocation = bundle.getLocation();

if (bundleLocation.contains(testWarFileName)) {
addingBundleCountDownLatch.countDown();

return bundle;
}

return null;
}

@Override
public void removedBundle(
Bundle bundle, BundleEvent bundleEvent, Bundle object) {

removeBundleCountDownLatch.countDown();
}

};

bundleTracker.open();

File testWarFileInDeployDir = new File(
PropsUtil.get(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR), testWarFileName);

Assert.assertFalse(testWarFileInDeployDir.exists());

File testWarFileInWarDir = new File(
PropsUtil.get(PropsKeys.MODULE_FRAMEWORK_WAR_DIR), testWarFileName);

Assert.assertFalse(testWarFileInWarDir.exists());

try {
File portalWarDir = new File(
PropsUtil.get("module.framework.portal.war.dir"));

File[] files = portalWarDir.listFiles();

File warFile = files[0];

Files.copy(warFile.toPath(), testWarFileInDeployDir.toPath());

addingBundleCountDownLatch.await();

Assert.assertFalse(testWarFileInDeployDir.exists());
Assert.assertTrue(testWarFileInWarDir.exists());
}
finally {
testWarFileInWarDir.delete();

removeBundleCountDownLatch.await();

bundleTracker.close();
}
}

}
9 changes: 9 additions & 0 deletions portal-impl/src/portal.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7928,6 +7928,7 @@
${module.framework.marketplace.dir},\
${module.framework.modules.dir},\
${module.framework.portal.dir},\
${module.framework.portal.war.dir},\
${module.framework.war.dir}

#
Expand Down Expand Up @@ -7978,6 +7979,14 @@
#
module.framework.portal.dir=${module.framework.base.dir}/portal

#
# Set the directory where the module framework portal WAR applications will
# be placed.
#
# Env: LIFERAY_MODULE_PERIOD_FRAMEWORK_PERIOD_PORTAL_MINUS_WAR_PERIOD_DIR
#
module.framework.portal.war.dir=${module.framework.base.dir}/portal-war

#
# Set the directory where the module framework WAR applications will be
# placed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ definition {

@priority = 3
test CustomizeNewWatchedDirectory {
property custom.properties = "module.framework.auto.deploy.dirs=${liferay.home}/alt-deploy/osgi/portal,${liferay.home}/osgi/modules,${liferay.home}/osgi/war,${liferay.home}/osgi/configs,${liferay.home}/osgi/marketplace";
property custom.properties = "module.framework.auto.deploy.dirs=${liferay.home}/alt-deploy/osgi/portal,${liferay.home}/osgi/configs,${liferay.home}/osgi/marketplace,${liferay.home}/osgi/modules,${liferay.home}/osgi/portal-war,${liferay.home}/osgi/war";
property test.liferay.virtual.instance = "false";
property test.run.type = "single";

Expand Down