Skip to content

Commit

Permalink
LPS-34598 Optional [conf] when we are retrieving dependencies. We wil…
Browse files Browse the repository at this point in the history
…l use this approach to handle provided dependencies in the OSGi bundles
  • Loading branch information
Miguel Pastor authored and brianchandotcom committed Apr 26, 2013
1 parent 7252b6d commit 11d9466
Show file tree
Hide file tree
Showing 48 changed files with 6,356 additions and 5 deletions.
20 changes: 15 additions & 5 deletions build-common-ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,27 @@
/>

<if>
<or>
<equals arg1="@{ivy.xml.dir}" arg2="${project.dir}" />
<antelope:endswith string="${ant.project.name}" with="-shared" />
</or>
<available file="@{ivy.xml.dir}/bnd.bnd" />
<then>
<ivy:retrieve
log="download-only"
pattern="@{ivy.xml.dir}/lib/[artifact].[ext]"
pattern="@{ivy.xml.dir}/lib/[conf]/[artifact].[ext]"
type="jar"
/>
</then>
<elseif>
<or>
<equals arg1="@{ivy.xml.dir}" arg2="${project.dir}" />
<antelope:endswith string="${ant.project.name}" with="-shared" />
</or>
<then>
<ivy:retrieve
log="download-only"
pattern="@{ivy.xml.dir}/docroot/WEB-INF/lib/[artifact].[ext]"
type="jar"
/>
</then>
</elseif>
<else>
<ivy:retrieve
log="download-only"
Expand Down
4 changes: 4 additions & 0 deletions build-common-osgi-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
</else>
</if>

<path id="plugin-lib.classpath">
<fileset dir="lib" includes="**/*.jar" />
</path>

<path id="osgi.plugin.classpath">
<path refid="portal.classpath" />
<path refid="plugin.classpath" />
Expand Down
30 changes: 30 additions & 0 deletions shared/http-service-shared/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>

<classpath>
<classpathentry excluding="**/.svn/**|.svn/" kind="src" path="src" />
<classpathentry kind="src" path="/portal-master" />
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" />
<classpathentry excluding="**/.svn/**|.svn/" kind="src" path="test/unit" />
<classpathentry kind="lib" path="/portal-master/lib/development/junit.jar" />
<classpathentry kind="lib" path="/portal-master/lib/development/mockito.jar" />
<classpathentry kind="lib" path="/portal-master/lib/development/powermock-mockito.jar" />
<classpathentry kind="lib" path="/portal-master/lib/development/spring-test.jar" />
<classpathentry kind="lib" path="/portal-master/lib/portal/commons-io.jar" />
<classpathentry kind="lib" path="/portal-master/lib/development/activation.jar" />
<classpathentry kind="lib" path="/portal-master/lib/development/annotations.jar" />
<classpathentry kind="lib" path="/portal-master/lib/development/jsp-api.jar" />
<classpathentry kind="lib" path="/portal-master/lib/development/mail.jar" />
<classpathentry kind="lib" path="/portal-master/lib/development/servlet-api.jar" />
<classpathentry kind="lib" path="/portal-master/lib/global/portlet.jar" />
<classpathentry kind="lib" path="/portal-master/lib/portal/commons-logging.jar" />
<classpathentry kind="lib" path="/portal-master/lib/portal/log4j.jar" />
<classpathentry kind="lib" path="/portal-master/portal-service/portal-service.jar" />
<classpathentry kind="lib" path="/portal-master/util-bridges/util-bridges.jar" />
<classpathentry kind="lib" path="/portal-master/util-java/util-java.jar" />
<classpathentry kind="lib" path="/portal-master/util-taglib/util-taglib.jar" />
<classpathentry kind="lib" path="lib/log-bridge-shared-6.2.0.1.jar" />
<classpathentry kind="lib" path="lib/portal-provided/axis.jar" />
<classpathentry kind="lib" path="lib/portal-provided/org.osgi.compendium.jar" />
<classpathentry kind="lib" path="lib/portal-provided/org.osgi.core.jar" />
<classpathentry kind="output" path="bin" />
</classpath>
1 change: 1 addition & 0 deletions shared/http-service-shared/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/lib/log-bridge-shared-*.jar
16 changes: 16 additions & 0 deletions shared/http-service-shared/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<projectDescription>
<name>http-service-shared-master</name>
<comment></comment>
<projects></projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments></arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions shared/http-service-shared/bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Bundle-Activator: com.liferay.httpservice.internal.HttpServiceActivator
Bundle-Name: Http Service
Export-Package:\
com.liferay.httpservice.servlet,\
com.liferay.httpservice.ws.*
Import-Package:\
com.liferay.httpservice.servlet,\
com.liferay.httpservice.ws.*,\
*
Include-Resource: classes
Private-Package:\
com.liferay.httpservice.internal.*
9 changes: 9 additions & 0 deletions shared/http-service-shared/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>

<project name="http-service-shared" basedir="." default="compile">
<property name="plugin.version" value="1" />

<import file="../../build-common-osgi-plugin.xml" />

<property name="import.shared" value="log-bridge-shared" />
</project>
13 changes: 13 additions & 0 deletions shared/http-service-shared/ivy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ivy-module version="2.0">
<info organisation="com.liferay" module="http-service-shared" />

<configurations>
<conf name="portal-provided" description="This depenndecies will be provided by the portal" />
</configurations>

<dependencies>
<dependency name="axis" org="org.apache.axis" rev="1.4" conf="portal-provided->*" />
<dependency name="org.osgi.compendium" org="org.osgi" rev="4.3.1" conf="portal-provided->*"/>
<dependency name="org.osgi.core" org="org.osgi" rev="4.3.1" conf="portal-provided->*"/>
</dependencies>
</ivy-module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.httpservice.internal;

import com.liferay.httpservice.internal.event.EventUtil;
import com.liferay.httpservice.internal.http.PortalHttpContext;
import com.liferay.httpservice.internal.servlet.BundleServletContext;
import com.liferay.httpservice.internal.servlet.WebExtenderServlet;
import com.liferay.httpservice.servlet.BundleServletConfig;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.Validator;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

/**
* @author Miguel Pastor
* @author Raymond Augé
*/
public class HttpServiceActivator
implements BundleActivator,
ServiceTrackerCustomizer<ServletContext, ServletContext> {

public ServletContext addingService(
ServiceReference<ServletContext> serviceReference) {

BundleContext bundleContext = getBundleContext();

ServletContext servletContext = bundleContext.getService(
serviceReference);

ServletConfig servletConfig = new BundleServletConfig(
servletContext, "Web Extender Servlet", null,
new PortalHttpContext(servletContext));

try {
_webExtenderServlet = new WebExtenderServlet(bundleContext);

_webExtenderServlet.init(servletConfig);

_webBundleDeployer = new WebBundleDeployer(_webExtenderServlet);

_startedBundleListener = new StartedBundleListener(
_webBundleDeployer);

bundleContext.addBundleListener(_startedBundleListener);

_stoppedBundleListener = new StoppedBundleListener(
_webBundleDeployer);

bundleContext.addBundleListener(_stoppedBundleListener);
}
catch (Exception e) {
_log.error(e, e);
}

checkStartableBundles();

return servletContext;
}

public BundleContext getBundleContext() {
return _bundleContext;
}

public void modifiedService(
ServiceReference<ServletContext> serviceReference,
ServletContext servletContext) {
}

public void removedService(
ServiceReference<ServletContext> serviceReference,
ServletContext servletContext) {

_webBundleDeployer.close();

_webBundleDeployer = null;

_webExtenderServlet.destroy();

_webExtenderServlet = null;

_bundleContext.removeBundleListener(_startedBundleListener);

_startedBundleListener = null;

_bundleContext.removeBundleListener(_stoppedBundleListener);

_stoppedBundleListener = null;
}

public void start(BundleContext bundleContext) throws Exception {
_bundleContext = bundleContext;

EventUtil.start(_bundleContext);

Filter filter = bundleContext.createFilter(
"(&(bean.id=" + ServletContext.class.getName() +
")(original.bean=*))");

_servletContextTracker =
new ServiceTracker<ServletContext, ServletContext>(
bundleContext, filter, this);

_servletContextTracker.open();
}

public void stop(BundleContext bundleContext) throws Exception {
_bundleContext = null;

_servletContextTracker.close();

_servletContextTracker = null;

EventUtil.close();
}

protected void checkStartableBundles() {
for (Bundle bundle : _bundleContext.getBundles()) {
String servletContextName =
BundleServletContext.getServletContextName(bundle);

if (Validator.isNull(servletContextName)) {
continue;
}

try {
_webBundleDeployer.doStart(bundle, servletContextName);
}
catch (Exception e) {
_log.error(e, e);
}
}
}

private static Log _log = LogFactoryUtil.getLog(HttpServiceActivator.class);

private BundleContext _bundleContext;
private StartedBundleListener _startedBundleListener;
private StoppedBundleListener _stoppedBundleListener;
private WebBundleDeployer _webBundleDeployer;
private WebExtenderServlet _webExtenderServlet;
private ServiceTracker<ServletContext, ServletContext>
_servletContextTracker;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.httpservice.internal;

import com.liferay.httpservice.internal.servlet.BundleServletContext;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.Validator;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;

/**
* @author Raymond Augé
* @author Miguel Pastor
*/
public class StartedBundleListener implements BundleListener {

public StartedBundleListener(WebBundleDeployer webBundleDeployer) {
_webBundleDeployer = webBundleDeployer;
}

public void bundleChanged(BundleEvent bundleEvent) {
int type = bundleEvent.getType();

Bundle bundle = bundleEvent.getBundle();

String servletContextName = BundleServletContext.getServletContextName(
bundle);

if (Validator.isNull(servletContextName)) {
return;
}

try {
if (type == BundleEvent.STARTED) {
_webBundleDeployer.doStart(bundle, servletContextName);
}
}
catch (Exception e) {
_log.error(e, e);
}
}

private static Log _log = LogFactoryUtil.getLog(
StartedBundleListener.class);

private WebBundleDeployer _webBundleDeployer;

}
Loading

0 comments on commit 11d9466

Please sign in to comment.