Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
GTNPC-100: PortalContext.VERSION needs to be updated for each release
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Apr 4, 2013
1 parent 1d437df commit 8853db3
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 88 deletions.
15 changes: 0 additions & 15 deletions api/src/main/java/org/gatein/pc/api/spi/PortalContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
******************************************************************************/
package org.gatein.pc.api.spi;

import org.gatein.common.util.Version;
import org.gatein.pc.api.WindowState;

import java.util.Map;
Expand All @@ -36,7 +35,6 @@
*/
public interface PortalContext
{
public static final Version VERSION = new Version("GateIn Portlet Container", 2, 4, 1, new Version.Qualifier(Version.Qualifier.Prefix.CR, Version.Qualifier.Suffix.SUFFIX_2), "Community");

/**
* Return info about the portal. Must conform to javax.portlet.PortalContext.getPortalInfo().
Expand Down Expand Up @@ -66,17 +64,4 @@ public interface PortalContext
*/
Map<String, String> getProperties();

Version.Format PORTLET_SPEC_FORMAT = new Version.Format()
{
public String toString(Version version)
{
StringBuffer buffer = new StringBuffer(version.getName());
buffer.append("/")
.append(version.getMajor()).append('.')
.append(version.getMinor()).append('.')
.append(version.getPatch()).append('-')
.append(version.getQualifier());
return buffer.toString();
}
};
}
103 changes: 103 additions & 0 deletions portlet/src/main/java/org/gatein/pc/portlet/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2012 eXo Platform SAS.
*
* This 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 software 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.gatein.pc.portlet;

import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* <p>Determine version information from the artifact metadata. When the version cannot be determined, the
* version <code>0.0.0-GA</code> is used.</p>
*
*
* <p>This class only uses classes provided by the Java Platform in order to be used without any further dependency.
* Information is logged through {@link java.util.logging.Logger} on purpose instead of any other logger.</p>
*
* <p>This class provides a main class that can be executed to check the version manually (hence the reason
* it does not depend on any other class than the Java Platform):</p>
*
* <code>java -cp target/pc-portlet-2.4.1.CR03-SNAPSHOT.jar org.gatein.pc.portlet.Version</code>
*
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
*/
public class Version
{

/** Major and minor extracted. */
private static final Pattern MAJOR_MINOR_PATTERN = Pattern.compile("^(\\d)+\\.(\\d)+");

/** . */
public static final String VALUE;

/** . */
public static final int MAJOR;

/** . */
public static final int MINOR;

static
{
String value = "0.0.0-GA";
int major = 0;
int minor = 0;
try
{
Properties props = new Properties();
InputStream in = Version.class.getResourceAsStream("/META-INF/maven/org.gatein.pc/pc-portlet/pom.properties");
if (in != null)
{
props.load(in);
String version = props.getProperty("version");
if (version != null)
{
version = version.trim();
if (version.length() > 0)
{
value = version.trim();
Matcher matcher = MAJOR_MINOR_PATTERN.matcher(value);
if (matcher.find())
{
major = Integer.parseInt(matcher.group(1));
minor = Integer.parseInt(matcher.group(2));
}
}
}
}
}
catch (Exception e)
{
Logger.getLogger(Version.class.getName()).log(Level.WARNING, "Could not load version from maven", e);
}
VALUE = value;
MAJOR = major;
MINOR = minor;
}

public static void main(String[] args)
{
System.out.println("version=" + VALUE);
System.out.println("major=" + MAJOR);
System.out.println("minor=" + MINOR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
******************************************************************************/
package org.gatein.pc.portlet.impl.jsr168.api;

import org.gatein.pc.portlet.Version;
import org.gatein.pc.portlet.impl.info.ContainerPortletApplicationInfo;
import org.gatein.pc.api.info.RuntimeOptionInfo;
import org.gatein.pc.api.spi.PortalContext;

import javax.portlet.PortletContext;
import javax.portlet.PortletRequestDispatcher;
Expand All @@ -50,18 +50,14 @@ public class PortletContextImpl implements PortletContext
/** . */
private ContainerPortletApplicationInfo info;

private static final String VERSION = PortalContext.VERSION.getName().replace(" ", "") + "/"
+ PortalContext.VERSION.getMajor() + "." + PortalContext.VERSION.getMinor() + "."
+ PortalContext.VERSION.getQualifier();

public PortletContextImpl(ServletContext servletContext)
{
this.servletContext = servletContext;
}

public String getServerInfo()
{
return VERSION;
return "GateInPC/" + Version.VALUE;
}

public PortletRequestDispatcher getRequestDispatcher(String path)
Expand Down Expand Up @@ -105,12 +101,12 @@ public InputStream getResourceAsStream(String s)

public int getMajorVersion()
{
return 2;
return Version.MAJOR;
}

public int getMinorVersion()
{
return 0;
return Version.MINOR;
}

public String getMimeType(String s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.gatein.pc.api.Mode;
import org.gatein.pc.api.WindowState;
import org.gatein.pc.api.spi.PortalContext;
import org.gatein.pc.portlet.Version;

import java.util.Collections;
import java.util.Map;
Expand All @@ -38,6 +39,11 @@
public class AbstractPortalContext implements PortalContext
{

/**
* The default info returned by the Portal.
* . */
public static final String DEFAULT_INFO = "GateIn/" + Version.VALUE;

/** . */
private static final Map<String, String> EMPTY_STRING_TO_STRING_MAP = Collections.emptyMap();

Expand Down Expand Up @@ -87,7 +93,7 @@ public AbstractPortalContext()

public String getInfo()
{
return PortalContext.PORTLET_SPEC_FORMAT.toString(VERSION);
return DEFAULT_INFO;
}

public Set<WindowState> getWindowStates()
Expand Down
43 changes: 0 additions & 43 deletions test/core/src/main/java/org/gatein/pc/test/unit/TestConstants.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
******************************************************************************/
package org.gatein.pc.test.portlet.jsr168.api.portalcontext;

import org.gatein.pc.api.spi.PortalContext;
import org.gatein.pc.test.unit.web.UTP1;
import org.gatein.pc.test.unit.Assertion;
import org.gatein.pc.test.unit.PortletTestCase;
Expand All @@ -36,7 +35,10 @@
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import static org.gatein.pc.test.unit.Assert.assertTrue;
import java.util.regex.Pattern;

import static org.gatein.pc.test.unit.Assert.assertNotNull;
import static org.gatein.pc.test.unit.Assert.fail;

/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
Expand All @@ -45,23 +47,22 @@
@TestCase({Assertion.API286_PORTAL_CONTEXT_2})
public class PortalInfo
{

/** . */
Pattern PATTERN = Pattern.compile("^[^/]+/[^/]+$");

public PortalInfo(PortletTestCase seq)
{
seq.bindAction(0, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
{
protected Response run(Portlet portlet, RenderRequest request, RenderResponse response, PortletTestContext context)
{
String info = request.getPortalContext().getPortalInfo();

assertTrue(info.length() > 0);

String[] components = info.split("/");
assertTrue(components.length == 2);
assertTrue(PortalContext.VERSION.getName().equals(components[0]));
String version = PortalContext.VERSION.getMajor() + "." + PortalContext.VERSION.getMinor() + "."
+ PortalContext.VERSION.getPatch() + "-" + PortalContext.VERSION.getQualifier();
assertTrue(version.equals(components[1]));

assertNotNull(info);
if (!PATTERN.matcher(info).matches())
{
fail("Bad portal context info " + info);
}
return new EndTestResponse();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ public class ServerInfo
{

/** . */
private static final String VERSION_REGEX = "GateInPortletContainer/[0-9]+\\.[0-9]+(|\\.CR[0-9]{2})(|\\.SNAPSHOT)(|\\.ALPHA[0-9]{2})(|\\.BETA[0-9]{2})(|\\.SP[0-9]{2})(|\\.CP[0-9]{2})(|\\.GA)";

/** . */
private static final Pattern VERSION_PATTERN = Pattern.compile(VERSION_REGEX, Pattern.CASE_INSENSITIVE);
private static final Pattern VERSION_PATTERN = Pattern.compile("GateInPC/[^/]+");

public ServerInfo(PortletTestCase seq)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
import org.gatein.pc.test.unit.web.UTP1;
import org.gatein.pc.test.unit.PortletTestCase;
import org.gatein.pc.test.unit.PortletTestContext;
import org.gatein.pc.test.unit.TestConstants;
import org.gatein.pc.test.unit.Assertion;
import org.gatein.pc.test.unit.actions.PortletRenderTestAction;
import org.gatein.pc.test.unit.annotations.TestCase;
import org.gatein.pc.test.unit.web.AbstractUniversalTestPortlet;
import static org.gatein.pc.test.unit.Assert.assertEquals;
import org.gatein.pc.test.unit.protocol.response.Response;
import org.gatein.pc.test.unit.protocol.response.EndTestResponse;

Expand All @@ -55,9 +53,9 @@ public Version(PortletTestCase seq)
protected Response run(Portlet portlet, RenderRequest request, RenderResponse response, PortletTestContext context)
{
AbstractUniversalTestPortlet aport = (AbstractUniversalTestPortlet)portlet;

assertEquals(TestConstants.MINOR_VERSION, aport.getPortletContext().getMinorVersion());
assertEquals(TestConstants.MAJOR_VERSION, aport.getPortletContext().getMajorVersion());
// Just test we can retrieve any value without an error
aport.getPortletContext().getMinorVersion();
aport.getPortletContext().getMajorVersion();
return new EndTestResponse();
}
});
Expand Down

18 comments on commit 8853db3

@metacosm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a backward-compatible change. In particular, this breaks WSRP and might impact other components since it removes publicly available fields. While we could adapt our other components, ideally, this is not a change that should target a minor release.

@vietj
Copy link
Contributor Author

@vietj vietj commented on 8853db3 Apr 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GateIn 3.6 (which is not a maintenance of 3.5)

Does it break WSRP in a way you cannot upgrade it trivially ?

If you are not able to upgrade WSRP then we will rollback this change.

@vietj
Copy link
Contributor Author

@vietj vietj commented on 8853db3 Apr 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I can still make it and keep the old field that would not be used anymore for keeping this compatiblity. So I will do that before the next release.

@vietj
Copy link
Contributor Author

@vietj vietj commented on 8853db3 Apr 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So keeping :

public static final Version VERSION = new Version("GateIn Portlet Container", 2, 4, 1, new Version.Qualifier(Version.Qualifier.Prefix.CR, Version.Qualifier.Suffix.SUFFIX_2), "Community");

Should be sufficient, can you confirm it ?

@metacosm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking now. Thanks. It shouldn't be too difficult to upgrade the components (I'm only aware of WSRP needing it at the moment) if needed. I just worry about public "API" changes in minor releases.

@vietj
Copy link
Contributor Author

@vietj vietj commented on 8853db3 Apr 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but you may use this in another an earlier wsrp branch and that would be an issue. isn't it the case ?

@metacosm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main point, I guess, is that the version (whatever form it takes) needs to be available from the API module. Currently, this information is used by WSRP as Consumer Agent identifying GateIn consumers with producers so who knows how this string is used by current users (theoretically, changing this string would amount to changing a browser user agent, though in practice, it most certainly doesn't have the same impact). See: https://github.com/gatein/gatein-wsrp/blob/master/common/src/main/java/org/gatein/wsrp/WSRPConstants.java#L163 to see how it's currently used.

@vietj
Copy link
Contributor Author

@vietj vietj commented on 8853db3 Apr 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you care about the portal version or the portlet container version ?

@metacosm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care about the specific versions but WSRP cares about the format of the value, it is used to register consumers as defined in the consumerAgent field of the RegistrationData structure: http://docs.oasis-open.org/wsrp/v2/wsrp-2.0-spec-os-01.html#_RegistrationData. Theoretically, producers could adapt content based on that string just as web servers adapt content based on user agent though I don't know that people actually do this with WSRP (especially considering Sharepoint doesn't even respect the consumerAgent format, for example).

@metacosm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the view to use the portlet container version since I would like our WSRP implementation to be independent of the portal it runs in (as a consumer). Its capabilities are mostly limited by what the portlet container can do, though, granted, a particular implementation in a specific portal might further restrict its capabilities.

@vietj
Copy link
Contributor Author

@vietj vietj commented on 8853db3 Apr 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no I mean that there are two versions:

1/ the portal version (i.e the PortalContext but the field gives the version of the PC)
2/ the portlet container version

I would like to know if you care about determining the version of the portal (gatein 3.5) or the version of the portlet container (gatein-pc 2.4)

@vietj
Copy link
Contributor Author

@vietj vietj commented on 8853db3 Apr 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so PC it is!

so this constant should not be on PortalContext at least :-)

@vietj
Copy link
Contributor Author

@vietj vietj commented on 8853db3 Apr 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the major / minor sufficient ? can you use the org.gatein.pc.portlet.Version#MAJOR and org.gatein.pc.portlet.Version#MINOR fields ?

@metacosm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can use Version since WSRP also depends on pc-portlet, not just pc-api. WSRP also needs a product name but I guess I could hardcode that in WSRP itself.

@metacosm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, not too sure what the format actually is. Version.Value is the whole String, right (so 2.4.1.CR03-SNAPSHOT at the moment). Version.MAJOR is 2 and Version.MINOR is 4 now, right? Would be nice to be able to get the rest of the version in a separate field as well.

@vietj
Copy link
Contributor Author

@vietj vietj commented on 8853db3 Apr 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be moved to the API package if needed (to determine the Version of the API). For the name it will not likely not change soon unless I fork it :-)

@vietj
Copy link
Contributor Author

@vietj vietj commented on 8853db3 Apr 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is exactly that. Parsing the patch rest could be easy to do if needed. I tool this approach to make things simpler too. The org.gatein.common Version object was a bit over engineered (by me :-) )

@vietj
Copy link
Contributor Author

@vietj vietj commented on 8853db3 Apr 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also JBoss changes version format every 2 years, without mentioning the 01 format for numbers introduced by Thomas :-)

Please sign in to comment.