Skip to content

Commit

Permalink
[backport] Add a tycho-eclipse-plugin
Browse files Browse the repository at this point in the history
Tycho already offers to run an eclipse application with the
tycho-extras/tycho-eclipserun-plugin, usually used to run an eclipse
application. Recently there was a demand to even execute a project "like
in eclipse", and there is even an (ant based) solution to run "tests in
eclipse".

Because of this it seem suitable to collect all these demands in a
plugin dedicated to eclipse task
  • Loading branch information
laeubi committed Nov 19, 2023
1 parent 1a75861 commit d1ced13
Show file tree
Hide file tree
Showing 23 changed files with 1,534 additions and 464 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ This page describes the noteworthy improvements provided by each release of Ecli
## 4.0.5

### backports:

- support for PDE Api Tools Annotations
- api tools fixes
- new `tycho-eclipse-plugin`

## 4.0.4

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@
<module>tycho-targetplatform</module>
<module>tycho-bnd-plugin</module>
<module>tycho-repository-plugin</module>
<module>tycho-eclipse-plugin</module>
</modules>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
Expand All @@ -29,8 +28,6 @@
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.metadata.MetadataFactory;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction;
import org.eclipse.tycho.BuildProperties;
Expand Down Expand Up @@ -67,7 +64,7 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
try (Processor processor = bndTychoProject.get()) {
List<IRequirement> requirements = getBndClasspathRequirements(processor);
if (!requirements.isEmpty()) {
return createIU(requirements);
return InstallableUnitProvider.createIU(requirements, "bnd-classpath-requirements");
}
} catch (IOException e) {
logger.warn("Can't determine classpath requirements from " + project.getId(), e);
Expand All @@ -80,7 +77,7 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
.map(bundleName -> MetadataFactory.createRequirement(BundlesAction.CAPABILITY_NS_OSGI_BUNDLE,
bundleName, VersionRange.emptyRange, null, true, true))
.toList();
return createIU(additionalBundleRequirements);
return InstallableUnitProvider.createIU(additionalBundleRequirements, "additional-bundle-requirements");
}
return Collections.emptyList();
}
Expand All @@ -97,15 +94,4 @@ public static List<IRequirement> getBndClasspathRequirements(Processor processor
return Collections.emptyList();
}

private Collection<IInstallableUnit> createIU(List<IRequirement> additionalBundleRequirements) {
if (additionalBundleRequirements.isEmpty()) {
return Collections.emptyList();
}
InstallableUnitDescription result = new MetadataFactory.InstallableUnitDescription();
result.setId("additional-bundle-requirements-" + UUID.randomUUID());
result.setVersion(Version.createOSGi(0, 0, 0, String.valueOf(System.currentTimeMillis())));
result.addRequirements(additionalBundleRequirements);
return List.of(MetadataFactory.createInstallableUnit(result));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.tycho.osgi.framework;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand All @@ -27,6 +28,7 @@
import java.util.Set;
import java.util.function.Predicate;

import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
Expand Down Expand Up @@ -61,8 +63,8 @@ public class EclipseApplication {

public static final String ARG_APPLICATION = "-application";

private static final Set<String> ALWAYS_START_BUNDLES = Set.of(Bundles.BUNDLE_CORE,
Bundles.BUNDLE_SCR, Bundles.BUNDLE_APP);
private static final Set<String> ALWAYS_START_BUNDLES = Set.of(Bundles.BUNDLE_CORE, Bundles.BUNDLE_SCR,
Bundles.BUNDLE_APP);
private P2Resolver resolver;
private TargetPlatform targetPlatform;
private Logger logger;
Expand All @@ -72,12 +74,15 @@ public class EclipseApplication {
private Map<String, String> frameworkProperties = new LinkedHashMap<>();
private Predicate<LogEntry> loggingFilter = always -> true;
private Set<String> startBundles = new HashSet<>(ALWAYS_START_BUNDLES);
private Map<File, MavenProject> baseDirMap;

EclipseApplication(String name, P2Resolver resolver, TargetPlatform targetPlatform, Logger logger) {
EclipseApplication(String name, P2Resolver resolver, TargetPlatform targetPlatform, Logger logger,
Map<File, MavenProject> baseDirMap) {
this.name = name;
this.resolver = resolver;
this.targetPlatform = targetPlatform;
this.logger = logger;
this.baseDirMap = baseDirMap;
}

public synchronized Collection<Path> getApplicationBundles() {
Expand All @@ -100,7 +105,18 @@ private List<Path> resolveBundles(P2Resolver resolver) {
for (Entry entry : result.getArtifacts()) {
if (ArtifactType.TYPE_ECLIPSE_PLUGIN.equals(entry.getType())
&& !"org.eclipse.osgi".equals(entry.getId())) {
resolvedBundles.add(entry.getLocation(true).toPath());
File location = entry.getLocation(true);
Path path = location.toPath();
if (location.isDirectory()) {
MavenProject mavenProject = baseDirMap.get(location);
if (mavenProject != null) {
File artifactFile = mavenProject.getArtifact().getFile();
if (artifactFile != null && artifactFile.exists()) {
path = artifactFile.toPath();
}
}
}
resolvedBundles.add(path);
}
}
}
Expand Down Expand Up @@ -187,10 +203,14 @@ public <T> EclipseFramework startFramework(EclipseWorkspace<T> workspace, List<S
Bundle bundle = systemBundleContext.getBundle(location);
if (bundle == null) {
//not installed yet...
try (InputStream stream = Files.newInputStream(bundleFile)) {
bundle = systemBundleContext.installBundle(location, stream);
} catch (IOException e) {
throw new BundleException("can't read bundle " + bundleFile, e);
if (Files.isDirectory(bundleFile)) {
bundle = systemBundleContext.installBundle(location);
} else {
try (InputStream stream = Files.newInputStream(bundleFile)) {
bundle = systemBundleContext.installBundle(location, stream);
} catch (IOException e) {
throw new BundleException("can't read bundle " + bundleFile, e);
}
}
}
if (startBundles.contains(bundle.getSymbolicName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.apache.maven.SessionScoped;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
Expand Down Expand Up @@ -64,7 +67,8 @@ public EclipseApplication createEclipseApplication(MavenRepositoryLocation repos

public EclipseApplication createEclipseApplication(TargetPlatform targetPlatform, String name) {
P2Resolver resolver = createResolver();
EclipseApplication application = new EclipseApplication(name, resolver, targetPlatform, logger);
EclipseApplication application = new EclipseApplication(name, resolver, targetPlatform, logger, mavenSession
.getAllProjects().stream().collect(Collectors.toMap(MavenProject::getBasedir, Function.identity())));
//add the bare minimum required ...
application.addBundle(Bundles.BUNDLE_CORE);
application.addBundle(Bundles.BUNDLE_SCR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,13 @@ public void printState() {
}
}

public boolean hasBundle(String bsn) {
for (Bundle bundle : framework.getBundleContext().getBundles()) {
if (bundle.getSymbolicName().equals(bsn)) {
return true;
}
}
return false;
}

}
8 changes: 8 additions & 0 deletions tycho-eclipse-plugin/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=17
80 changes: 80 additions & 0 deletions tycho-eclipse-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho</artifactId>
<version>4.0.5-SNAPSHOT</version>
</parent>
<artifactId>tycho-eclipse-plugin</artifactId>
<name>Tycho Eclipse Plugin</name>
<packaging>maven-plugin</packaging>
<prerequisites>
<maven>${minimal-maven-version}</maven>
</prerequisites>
<description>Maven Plugins for working with Eclipse</description>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.pde</groupId>
<artifactId>org.eclipse.pde.core</artifactId>
<version>3.17.100</version>
<type>jar</type>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>sisu-equinox-launching</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-testing-harness</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. 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:
* - Mickael Istria (Red Hat Inc.)
*******************************************************************************/
package org.eclipse.tycho.eclipsebuild;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.pde.core.target.ITargetDefinition;
import org.eclipse.pde.core.target.ITargetLocation;
import org.eclipse.pde.core.target.TargetBundle;
import org.eclipse.pde.core.target.TargetFeature;

class BundleListTargetLocation implements ITargetLocation {

private TargetBundle[] bundles;

public BundleListTargetLocation(TargetBundle[] bundles) {
this.bundles = bundles;
}

@Override
public <T> T getAdapter(Class<T> adapter) {
return null;
}

@Override
public IStatus resolve(ITargetDefinition definition, IProgressMonitor monitor) {
return Status.OK_STATUS;
}

@Override
public boolean isResolved() {
return true;
}

@Override
public IStatus getStatus() {
return Status.OK_STATUS;
}

@Override
public String getType() {
return "BundleList"; //$NON-NLS-1$
}

@Override
public String getLocation(boolean resolve) throws CoreException {
return null;
}

@Override
public TargetBundle[] getBundles() {
return this.bundles;
}

@Override
public TargetFeature[] getFeatures() {
return null;
}

@Override
public String[] getVMArguments() {
return null;
}

@Override
public String serialize() {
return null;
}

}

0 comments on commit d1ced13

Please sign in to comment.