Skip to content

Commit

Permalink
Implement the OSGi-Framework-Connect on to p of Plexus
Browse files Browse the repository at this point in the history
OSGi provides a new specification that allows powerful integration of
"outside" bundles into a framework.

Tycho can leverage this to have a seamless integration with the P2 code
that requires OSGi to run but still interact with the OSGi parts without
additional integration/conversion patterns.
  • Loading branch information
laeubi committed Jul 19, 2022
1 parent 2899550 commit 6d77039
Show file tree
Hide file tree
Showing 14 changed files with 998 additions and 396 deletions.
104 changes: 101 additions & 3 deletions p2-maven-plugin/pom.xml
Expand Up @@ -72,9 +72,19 @@
<version>1.4.100</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.frameworkadmin</artifactId>
<version>2.2.0</version>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.frameworkadmin</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
<version>3.10.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.security</artifactId>
<version>1.3.800</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -107,6 +117,94 @@
<artifactId>tycho-embedder-api</artifactId>
<version>${project.version}</version>
</dependency>
<!-- P2 -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.p2.jarprocessor</artifactId>
<version>1.2.300</version>
</dependency>
<!-- Equinox -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.concurrent</artifactId>
<version>1.2.100</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.simpleconfigurator</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.app</artifactId>
<version>1.6.100</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.frameworkadmin.equinox</artifactId>
<version>1.2.200</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.simpleconfigurator.manipulator</artifactId>
<version>2.2.0</version>
</dependency>
<!-- ECF -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.p2.transport.ecf</artifactId>
<version>1.3.300</version>
</dependency>
<dependency>
<groupId>org.eclipse.ecf</groupId>
<artifactId>org.eclipse.ecf.identity</artifactId>
<version>3.9.402</version>
</dependency>
<dependency>
<groupId>org.eclipse.ecf</groupId>
<artifactId>org.eclipse.ecf.provider.filetransfer</artifactId>
<version>3.2.800</version>
</dependency>
<dependency>
<groupId>org.eclipse.ecf</groupId>
<artifactId>org.eclipse.ecf.filetransfer</artifactId>
<version>5.1.102</version>
</dependency>
<dependency>
<groupId>org.eclipse.ecf</groupId>
<artifactId>org.eclipse.ecf</artifactId>
<version>3.10.0</version>
</dependency>

<!-- felix -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr</artifactId>
<version>2.2.2</version>
</dependency>
<!-- OSGi API -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component</artifactId>
<version>1.5.0</version>
</dependency>
<!-- others -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpg-jdk15on</artifactId>
<version>1.70</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.70</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>

</dependencies>

<build>
Expand Down

This file was deleted.

Expand Up @@ -33,6 +33,8 @@
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
Expand All @@ -53,15 +55,17 @@
import org.eclipse.tycho.p2maven.actions.ProductFile2;
import org.eclipse.tycho.p2maven.helper.PluginRealmHelper;
import org.eclipse.tycho.p2maven.io.MetadataIO;
import org.osgi.framework.BundleContext;
import org.eclipse.tycho.plexus.osgi.PlexusFrameworkConnectFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.xml.sax.SAXException;

/**
* Component used to generate {@link IInstallableUnit}s from other artifacts
*
*/
@Component(role = InstallableUnitGenerator.class)
public class InstallableUnitGenerator {
public class InstallableUnitGenerator implements Initializable {

private static final boolean DUMP_DATA = Boolean.getBoolean("tycho.p2.dump")
|| Boolean.getBoolean("tycho.p2.dump.units");
Expand All @@ -71,9 +75,8 @@ public class InstallableUnitGenerator {

private static final String KEY_UNITS = "InstallableUnitGenerator.units";

// this requirement is here to bootstrap P2 service access
@Requirement(hint = "plexus")
private BundleContext bundleContext;
@Requirement
private PlexusFrameworkConnectFactory frameworkFactory;

@Requirement(role = InstallableUnitProvider.class)
private Map<String, InstallableUnitProvider> additionalUnitProviders;
Expand Down Expand Up @@ -271,4 +274,23 @@ private static boolean hasPluginDependency(PluginDescriptor pluginDescriptor) {
.filter(dep -> P2Plugin.ARTIFACT_ID.equals(dep.getArtifactId())).findAny().isPresent();
}

@Override
public void initialize() throws InitializationException {
try {
for (Bundle bundle : frameworkFactory.getFramework(P2Plugin.class).getBundleContext().getBundles()) {
// see https://github.com/eclipse-equinox/p2/issues/100
if ("org.eclipse.equinox.p2.publisher.eclipse".equals(bundle.getSymbolicName())) {
try {
bundle.start();
} catch (BundleException e) {
log.warn("Can't start bundle " + bundle.getSymbolicName(), e);
}
break;
}
}
} catch (BundleException e) {
log.error("Can't init OSGi framework!");
}
}

}
@@ -0,0 +1,75 @@
/*******************************************************************************
* Copyright (c) 2022 Christoph Läubrich and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.tycho.p2maven;

import java.util.concurrent.atomic.AtomicBoolean;

import org.codehaus.plexus.logging.Logger;
import org.eclipse.core.runtime.IProgressMonitor;

public class LoggerProgressMonitor implements IProgressMonitor {

private final Logger log;

private AtomicBoolean canceled = new AtomicBoolean();

public LoggerProgressMonitor(Logger log) {
this.log = log;
}

@Override
public void worked(int work) {

}

@Override
public void subTask(String name) {
if (name != null && !name.isBlank()) {
log.debug(name);
}
}

@Override
public void setTaskName(String name) {
if (name != null && !name.isBlank()) {
log.info(name);
}
}

@Override
public void setCanceled(boolean value) {
canceled.set(value);
}

@Override
public boolean isCanceled() {
return canceled.get();
}

@Override
public void internalWorked(double work) {

}

@Override
public void done() {

}

@Override
public void beginTask(String name, int totalWork) {
if (name != null && !name.isBlank()) {
log.info(name);
}
}
}

0 comments on commit 6d77039

Please sign in to comment.