Skip to content

Commit

Permalink
transform the bundle symbolic name 'system.bundle', issue #104
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Jun 8, 2015
1 parent 6e2b9cf commit a76a69c
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 15 deletions.
1 change: 1 addition & 0 deletions de.dentrassi.pm.aspect.common/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ Export-Package: de.dentrassi.pm.aspect.common.osgi;version="1.0.0";
de.dentrassi.pm.osgi.bundle,
de.dentrassi.pm.aspect.extract,
de.dentrassi.pm.osgi.feature",
de.dentrassi.pm.aspect.common.p2;version="1.0.0",
de.dentrassi.pm.aspect.common.spool;version="1.0.0";uses:="de.dentrassi.pm.common.utils,de.dentrassi.pm.aspect.aggregate"
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class InstallableUnit
{
private final static Logger logger = LoggerFactory.getLogger ( InstallableUnit.class );

private static final String DEFAULT_SYSTEM_BUNDLE_ALIAS = "org.eclipse.osgi";

private String id;

private Version version;
Expand Down Expand Up @@ -528,6 +530,11 @@ private static InstallableUnit createFeatureGroup ( final FeatureInformation fea
}

public static InstallableUnit fromBundle ( final BundleInformation bundle )
{
return fromBundle ( bundle, null );
}

public static InstallableUnit fromBundle ( final BundleInformation bundle, final P2MetaDataInformation info )
{
final InstallableUnit result = new InstallableUnit ();

Expand Down Expand Up @@ -566,9 +573,11 @@ public static InstallableUnit fromBundle ( final BundleInformation bundle )
result.getRequires ().put ( new Key ( "java.package", pi.getName () ), new Requirement ( pi.getVersionRange (), pi.isOptional (), pi.isOptional () ? false : null, null ) );
}

final String systemBundleAlias = getSystemBundleAlias ( info );

for ( final BundleRequirement br : bundle.getBundleRequirements () )
{
result.getRequires ().put ( new Key ( "osgi.bundle", br.getId () ), new Requirement ( br.getVersionRange (), br.isOptional (), br.isOptional () ? false : null, null ) );
result.getRequires ().put ( new Key ( "osgi.bundle", transformBundleName ( systemBundleAlias, br.getId () ) ), new Requirement ( br.getVersionRange (), br.isOptional (), br.isOptional () ? false : null, null ) );
}

// artifacts
Expand All @@ -583,7 +592,7 @@ public static InstallableUnit fromBundle ( final BundleInformation bundle )

try
{
final Map<String, String> td = new HashMap<String, String> ();
final Map<String, String> td = new HashMap<String, String> ( 1 );
td.put ( "manifest", makeManifest ( bundle.getId (), bundle.getVersion () ) );
addTouchpoint ( root, "org.eclipse.equinox.p2.osgi", "1.0.0", td );
}
Expand All @@ -597,6 +606,30 @@ public static InstallableUnit fromBundle ( final BundleInformation bundle )
return result;
}

private static String getSystemBundleAlias ( final P2MetaDataInformation info )
{
if ( info.getSystemBundleAlias () != null && !info.getSystemBundleAlias ().isEmpty () )
{
return info.getSystemBundleAlias ();
}
else
{
return DEFAULT_SYSTEM_BUNDLE_ALIAS;
}
}

private static String transformBundleName ( final String systemBundleAlias, final String id )
{
if ( id.equals ( Constants.SYSTEM_BUNDLE_SYMBOLICNAME ) )
{
return systemBundleAlias;
}
else
{
return id;
}
}

/**
* Add property entry only of value is not null
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import de.dentrassi.pm.aspect.ChannelAspect;
import de.dentrassi.pm.aspect.ChannelAspectFactory;
import de.dentrassi.pm.aspect.common.p2.internal.P2Virtualizer;
import de.dentrassi.pm.aspect.virtual.Virtualizer;

public class P2MetaDataAspectFactory implements ChannelAspectFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
* Contributors:
* IBH SYSTEMS GmbH - initial API and implementation
*******************************************************************************/
package de.dentrassi.pm.p2.web;
package de.dentrassi.pm.aspect.common.p2;

import de.dentrassi.pm.common.MetaKeyBinding;

public class P2MetaDataInformation
{
@MetaKeyBinding ( namespace = P2InterfaceExtender.P2_METADATA_ASPECT_ID, key = "system-bundle-alias" )
@MetaKeyBinding ( namespace = P2MetaDataAspectFactory.ID, key = "system-bundle-alias" )
private String systemBundleAlias;

public void setSystemBundleAlias ( final String systemBundleAlias )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import de.dentrassi.pm.aspect.ChannelAspect;
import de.dentrassi.pm.aspect.ChannelAspectFactory;
import de.dentrassi.pm.aspect.common.p2.internal.P2Unzipper;
import de.dentrassi.pm.aspect.virtual.Virtualizer;
import de.dentrassi.pm.common.MetaKey;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Contributors:
* IBH SYSTEMS GmbH - initial API and implementation
*******************************************************************************/
package de.dentrassi.pm.aspect.common.p2;
package de.dentrassi.pm.aspect.common.p2.internal;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
Expand All @@ -21,6 +21,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.dentrassi.pm.aspect.common.p2.P2UnzipAspectFactory;
import de.dentrassi.pm.aspect.virtual.Virtualizer;
import de.dentrassi.pm.common.ArtifactInformation;
import de.dentrassi.pm.common.MetaKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* Contributors:
* IBH SYSTEMS GmbH - initial API and implementation
*******************************************************************************/
package de.dentrassi.pm.aspect.common.p2;
package de.dentrassi.pm.aspect.common.p2.internal;

import static de.dentrassi.pm.common.XmlHelper.addElement;
import static de.dentrassi.pm.common.XmlHelper.fixSize;

import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.Map;

import org.osgi.framework.Version;
import org.slf4j.Logger;
Expand All @@ -23,9 +24,12 @@
import org.w3c.dom.Element;

import de.dentrassi.pm.aspect.common.osgi.OsgiAspectFactory;
import de.dentrassi.pm.aspect.common.p2.InstallableUnit;
import de.dentrassi.pm.aspect.common.p2.P2MetaDataInformation;
import de.dentrassi.pm.aspect.virtual.Virtualizer;
import de.dentrassi.pm.common.ArtifactInformation;
import de.dentrassi.pm.common.MetaKey;
import de.dentrassi.pm.common.MetaKeys;
import de.dentrassi.pm.common.SimpleArtifactInformation;
import de.dentrassi.pm.common.XmlHelper;
import de.dentrassi.pm.osgi.bundle.BundleInformation;
Expand Down Expand Up @@ -59,23 +63,27 @@ private void processVirtualize ( final Context context ) throws Exception
{
final ArtifactInformation art = context.getArtifactInformation ();

final Map<MetaKey, String> metaData = context.getProvidedChannelMetaData ();
final P2MetaDataInformation info = new P2MetaDataInformation ();
MetaKeys.bind ( info, metaData );

logger.debug ( "Process virtualize - artifactId: {} / {}", art.getId (), art.getName () );

final BundleInformation bi = OsgiAspectFactory.fetchBundleInformation ( art.getMetaData () );
if ( bi != null )
{
logger.debug ( "Process as bundle: {} ({})- {}", art.getName (), art.getId (), bi );
createBundleP2MetaData ( context, art, bi );
createBundleP2Artifacts ( context, art, bi );
createBundleP2MetaData ( context, info, art, bi );
createBundleP2Artifacts ( context, info, art, bi );
return;
}

final FeatureInformation fi = OsgiAspectFactory.fetchFeatureInformation ( art.getMetaData () );
if ( fi != null )
{
logger.debug ( "Process as feature: {} ({}) - {}", art.getName (), art.getId (), fi );
createFeatureP2MetaData ( context, art, fi );
createFeatureP2Artifacts ( context, art, fi );
createFeatureP2MetaData ( context, info, art, fi );
createFeatureP2Artifacts ( context, info, art, fi );
return;
}
}
Expand Down Expand Up @@ -112,12 +120,12 @@ private void createP2Artifacts ( final Context context, final String id, final V
createXmlVirtualArtifact ( context, artifact, doc, "-p2artifacts.xml" );
}

private void createFeatureP2Artifacts ( final Context context, final ArtifactInformation artifact, final FeatureInformation fi ) throws Exception
private void createFeatureP2Artifacts ( final Context context, final P2MetaDataInformation info, final ArtifactInformation artifact, final FeatureInformation fi ) throws Exception
{
createP2Artifacts ( context, fi.getId (), fi.getVersion (), "org.eclipse.update.feature", artifact, "application/zip" );
}

private void createBundleP2Artifacts ( final Context context, final ArtifactInformation artifact, final BundleInformation bi ) throws Exception
private void createBundleP2Artifacts ( final Context context, final P2MetaDataInformation info, final ArtifactInformation artifact, final BundleInformation bi ) throws Exception
{
createP2Artifacts ( context, bi.getId (), bi.getVersion (), "osgi.bundle", artifact, null );
}
Expand All @@ -134,15 +142,15 @@ private void addProperty ( final Element props, final String key, final String v
p.setAttribute ( "value", value );
}

private void createFeatureP2MetaData ( final Context context, final SimpleArtifactInformation art, final FeatureInformation fi ) throws Exception
private void createFeatureP2MetaData ( final Context context, final P2MetaDataInformation info, final SimpleArtifactInformation art, final FeatureInformation fi ) throws Exception
{
final List<InstallableUnit> ius = InstallableUnit.fromFeature ( fi );
createXmlVirtualArtifact ( context, art, InstallableUnit.toXml ( ius ), "-p2metadata.xml" );
}

private void createBundleP2MetaData ( final Context context, final SimpleArtifactInformation art, final BundleInformation bi ) throws Exception
private void createBundleP2MetaData ( final Context context, final P2MetaDataInformation info, final SimpleArtifactInformation art, final BundleInformation bi ) throws Exception
{
createXmlVirtualArtifact ( context, art, InstallableUnit.fromBundle ( bi ).toXml (), "-p2metadata.xml" );
createXmlVirtualArtifact ( context, art, InstallableUnit.fromBundle ( bi, info ).toXml (), "-p2metadata.xml" );
}

private void createXmlVirtualArtifact ( final Context context, final SimpleArtifactInformation art, final Document doc, final String suffix ) throws Exception
Expand Down
1 change: 1 addition & 0 deletions de.dentrassi.pm.p2.web/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Import-Package: de.dentrassi.osgi.web;version="1.0.0",
de.dentrassi.osgi.web.controller;version="1.0.0",
de.dentrassi.osgi.web.controller.binding;version="1.0.0",
de.dentrassi.osgi.web.controller.form;version="1.0.0",
de.dentrassi.pm.aspect.common.p2;version="1.0.0",
de.dentrassi.pm.common;version="1.0.0",
de.dentrassi.pm.common.web;version="1.0.0",
de.dentrassi.pm.common.web.menu;version="1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import de.dentrassi.osgi.web.controller.binding.BindingResult;
import de.dentrassi.osgi.web.controller.binding.PathVariable;
import de.dentrassi.osgi.web.controller.form.FormData;
import de.dentrassi.pm.aspect.common.p2.P2MetaDataInformation;
import de.dentrassi.pm.common.MetaKey;
import de.dentrassi.pm.common.MetaKeys;
import de.dentrassi.pm.common.web.CommonController;
Expand Down

0 comments on commit a76a69c

Please sign in to comment.