Skip to content

Commit

Permalink
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 18, 2023
1 parent e744b57 commit 550854f
Show file tree
Hide file tree
Showing 15 changed files with 932 additions and 6 deletions.
26 changes: 26 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@ If you are reading this in the browser, then you can quickly jump to specific ve

## 5.0.0 (under development)

### new `tycho-eclipse-plugin`

Tycho now contains a new `tycho-eclipse-plugin` that is dedicated to executing "tasks like eclipse", this currently includes
- the former tycho-extras `tycho-eclipserun-plugin` and its mojos
- a new `eclipse-build` mojo that allows to take a literal eclipse project and execute the build on it

#### new `eclipse-build` mojo

The `eclipse-build` mojo can be used like this

```xml
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-eclipse-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>eclipse-build</id>
<goals>
<goal>eclipse-build</goal>
</goals>
</execution>
</executions>
</plugin>
```

### support for PDE Api Tools Annotations

Tycho now supports PDE Api Tools Annotations to be added to the project automatically.
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 @@ -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
65 changes: 65 additions & 0 deletions tycho-eclipse-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<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>5.0.0-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>
</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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*******************************************************************************
* Copyright (c) 2023 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.eclipsebuild;

import java.io.IOException;
import java.io.Serializable;
import java.nio.file.Path;
import java.util.concurrent.Callable;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;

public class EclipseBuild implements Callable<EclipseBuildResult>, Serializable {

private boolean debug;
private String baseDir;

EclipseBuild(Path projectDir, boolean debug) {
this.debug = debug;
this.baseDir = pathAsString(projectDir);
}

@Override
public EclipseBuildResult call() throws Exception {
EclipseBuildResult result = new EclipseBuildResult();
Platform.addLogListener((status, plugin) -> debug(status.toString()));
disableAutoBuild();
deleteAllProjects();
IProject project = importProject();
IProgressMonitor debugMonitor = new IProgressMonitor() {

@Override
public void worked(int work) {

}

@Override
public void subTask(String name) {
debug("SubTask: " + name);
}

@Override
public void setTaskName(String name) {
debug("Task: " + name);
}

@Override
public void setCanceled(boolean value) {

}

@Override
public boolean isCanceled() {
return false;
}

@Override
public void internalWorked(double work) {

}

@Override
public void done() {

}

@Override
public void beginTask(String name, int totalWork) {
setTaskName(name);
}
};
project.build(IncrementalProjectBuilder.CLEAN_BUILD, debugMonitor);
project.build(IncrementalProjectBuilder.FULL_BUILD, debugMonitor);
for (IMarker marker : project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)) {
result.addMarker(marker);
debug(marker.toString());
}
ResourcesPlugin.getWorkspace().save(true, new NullProgressMonitor());
return result;
}

static void disableAutoBuild() throws CoreException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceDescription desc = workspace.getDescription();
desc.setAutoBuilding(false);
workspace.setDescription(desc);
}

private void deleteAllProjects() throws CoreException {
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
project.delete(IResource.NEVER_DELETE_PROJECT_CONTENT | IResource.FORCE, new NullProgressMonitor());
}
}

private IProject importProject() throws CoreException, IOException {
IPath projectPath = IPath.fromOSString(baseDir);
IPath projectDescriptionFile = projectPath.append(IProjectDescription.DESCRIPTION_FILE_NAME);
IProjectDescription projectDescription = ResourcesPlugin.getWorkspace()
.loadProjectDescription(projectDescriptionFile);
projectDescription.setLocation(projectPath);
// projectDescription.setBuildSpec(new ICommand[0]);
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectDescription.getName());
project.create(projectDescription, new NullProgressMonitor());
project.open(new NullProgressMonitor());
return project;
}

private void debug(String string) {
if (debug) {
System.out.println(string);
}
}

static String pathAsString(Path path) {
if (path != null) {
return path.toAbsolutePath().toString();
}
return null;
}

}
Loading

0 comments on commit 550854f

Please sign in to comment.