Skip to content

Commit 2b94427

Browse files
committed
Add a tycho-eclipse-plugin
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
1 parent e744b57 commit 2b94427

File tree

16 files changed

+944
-13
lines changed

16 files changed

+944
-13
lines changed

RELEASE_NOTES.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@ If you are reading this in the browser, then you can quickly jump to specific ve
66

77
## 5.0.0 (under development)
88

9+
### new `tycho-eclipse-plugin`
10+
11+
Tycho now contains a new `tycho-eclipse-plugin` that is dedicated to executing "tasks like eclipse", this currently includes
12+
- the former tycho-extras `tycho-eclipserun-plugin` and its mojos
13+
- a new `eclipse-build` mojo that allows to take a literal eclipse project and execute the build on it
14+
15+
#### new `eclipse-build` mojo
16+
17+
The `eclipse-build` mojo can be used like this
18+
19+
```xml
20+
<plugin>
21+
<groupId>org.eclipse.tycho</groupId>
22+
<artifactId>tycho-eclipse-plugin</artifactId>
23+
<version>${tycho-version}</version>
24+
<executions>
25+
<execution>
26+
<id>eclipse-build</id>
27+
<goals>
28+
<goal>eclipse-build</goal>
29+
</goals>
30+
</execution>
31+
</executions>
32+
</plugin>
33+
```
34+
935
### support for PDE Api Tools Annotations
1036

1137
Tycho now supports PDE Api Tools Annotations to be added to the project automatically.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@
557557
<module>tycho-targetplatform</module>
558558
<module>tycho-bnd-plugin</module>
559559
<module>tycho-repository-plugin</module>
560+
<module>tycho-eclipse-plugin</module>
560561
</modules>
561562
<profiles>
562563
<profile>

tycho-core/src/main/java/org/eclipse/tycho/osgi/framework/EclipseFramework.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,13 @@ public void printState() {
182182
}
183183
}
184184

185+
public boolean hasBundle(String bsn) {
186+
for (Bundle bundle : framework.getBundleContext().getBundles()) {
187+
if (bundle.getSymbolicName().equals(bsn)) {
188+
return true;
189+
}
190+
}
191+
return false;
192+
}
193+
185194
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
3+
org.eclipse.jdt.core.compiler.compliance=17
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7+
org.eclipse.jdt.core.compiler.release=disabled
8+
org.eclipse.jdt.core.compiler.source=17

tycho-eclipse-plugin/pom.xml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.eclipse.tycho</groupId>
7+
<artifactId>tycho</artifactId>
8+
<version>5.0.0-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>tycho-eclipse-plugin</artifactId>
11+
<name>Tycho Eclipse Plugin</name>
12+
<packaging>maven-plugin</packaging>
13+
<prerequisites>
14+
<maven>${minimal-maven-version}</maven>
15+
</prerequisites>
16+
<description>Maven Plugins for working with Eclipse</description>
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.apache.maven</groupId>
20+
<artifactId>maven-core</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.apache.maven</groupId>
24+
<artifactId>maven-plugin-api</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.maven.plugin-tools</groupId>
28+
<artifactId>maven-plugin-annotations</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.codehaus.plexus</groupId>
32+
<artifactId>plexus-utils</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.eclipse.tycho</groupId>
36+
<artifactId>tycho-core</artifactId>
37+
<version>${project.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.eclipse.pde</groupId>
41+
<artifactId>org.eclipse.pde.core</artifactId>
42+
<version>3.17.100</version>
43+
<type>jar</type>
44+
<exclusions>
45+
<exclusion>
46+
<groupId>*</groupId>
47+
<artifactId>*</artifactId>
48+
</exclusion>
49+
</exclusions>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.eclipse.tycho</groupId>
53+
<artifactId>sisu-equinox-launching</artifactId>
54+
<version>${project.version}</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.eclipse.tycho</groupId>
58+
<artifactId>tycho-testing-harness</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.mockito</groupId>
63+
<artifactId>mockito-core</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.apache.maven</groupId>
68+
<artifactId>maven-compat</artifactId>
69+
<scope>test</scope>
70+
</dependency>
71+
</dependencies>
72+
<build>
73+
<plugins>
74+
<plugin>
75+
<groupId>org.codehaus.plexus</groupId>
76+
<artifactId>plexus-component-metadata</artifactId>
77+
</plugin>
78+
</plugins>
79+
</build>
80+
</project>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2019 Red Hat Inc. and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* - Mickael Istria (Red Hat Inc.)
13+
*******************************************************************************/
14+
package org.eclipse.tycho.eclipsebuild;
15+
16+
import org.eclipse.core.runtime.CoreException;
17+
import org.eclipse.core.runtime.IProgressMonitor;
18+
import org.eclipse.core.runtime.IStatus;
19+
import org.eclipse.core.runtime.Status;
20+
import org.eclipse.pde.core.target.ITargetDefinition;
21+
import org.eclipse.pde.core.target.ITargetLocation;
22+
import org.eclipse.pde.core.target.TargetBundle;
23+
import org.eclipse.pde.core.target.TargetFeature;
24+
25+
class BundleListTargetLocation implements ITargetLocation {
26+
27+
private TargetBundle[] bundles;
28+
29+
public BundleListTargetLocation(TargetBundle[] bundles) {
30+
this.bundles = bundles;
31+
}
32+
33+
@Override
34+
public <T> T getAdapter(Class<T> adapter) {
35+
return null;
36+
}
37+
38+
@Override
39+
public IStatus resolve(ITargetDefinition definition, IProgressMonitor monitor) {
40+
return Status.OK_STATUS;
41+
}
42+
43+
@Override
44+
public boolean isResolved() {
45+
return true;
46+
}
47+
48+
@Override
49+
public IStatus getStatus() {
50+
return Status.OK_STATUS;
51+
}
52+
53+
@Override
54+
public String getType() {
55+
return "BundleList"; //$NON-NLS-1$
56+
}
57+
58+
@Override
59+
public String getLocation(boolean resolve) throws CoreException {
60+
return null;
61+
}
62+
63+
@Override
64+
public TargetBundle[] getBundles() {
65+
return this.bundles;
66+
}
67+
68+
@Override
69+
public TargetFeature[] getFeatures() {
70+
return null;
71+
}
72+
73+
@Override
74+
public String[] getVMArguments() {
75+
return null;
76+
}
77+
78+
@Override
79+
public String serialize() {
80+
return null;
81+
}
82+
83+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Christoph Läubrich and others.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.tycho.eclipsebuild;
14+
15+
import java.io.IOException;
16+
import java.io.Serializable;
17+
import java.nio.file.Path;
18+
import java.util.concurrent.Callable;
19+
20+
import org.eclipse.core.resources.IMarker;
21+
import org.eclipse.core.resources.IProject;
22+
import org.eclipse.core.resources.IProjectDescription;
23+
import org.eclipse.core.resources.IResource;
24+
import org.eclipse.core.resources.IWorkspace;
25+
import org.eclipse.core.resources.IWorkspaceDescription;
26+
import org.eclipse.core.resources.IncrementalProjectBuilder;
27+
import org.eclipse.core.resources.ResourcesPlugin;
28+
import org.eclipse.core.runtime.CoreException;
29+
import org.eclipse.core.runtime.IPath;
30+
import org.eclipse.core.runtime.IProgressMonitor;
31+
import org.eclipse.core.runtime.NullProgressMonitor;
32+
import org.eclipse.core.runtime.Platform;
33+
34+
public class EclipseBuild implements Callable<EclipseBuildResult>, Serializable {
35+
36+
private boolean debug;
37+
private String baseDir;
38+
39+
EclipseBuild(Path projectDir, boolean debug) {
40+
this.debug = debug;
41+
this.baseDir = pathAsString(projectDir);
42+
}
43+
44+
@Override
45+
public EclipseBuildResult call() throws Exception {
46+
EclipseBuildResult result = new EclipseBuildResult();
47+
Platform.addLogListener((status, plugin) -> debug(status.toString()));
48+
disableAutoBuild();
49+
deleteAllProjects();
50+
IProject project = importProject();
51+
IProgressMonitor debugMonitor = new IProgressMonitor() {
52+
53+
@Override
54+
public void worked(int work) {
55+
56+
}
57+
58+
@Override
59+
public void subTask(String name) {
60+
debug("SubTask: " + name);
61+
}
62+
63+
@Override
64+
public void setTaskName(String name) {
65+
debug("Task: " + name);
66+
}
67+
68+
@Override
69+
public void setCanceled(boolean value) {
70+
71+
}
72+
73+
@Override
74+
public boolean isCanceled() {
75+
return false;
76+
}
77+
78+
@Override
79+
public void internalWorked(double work) {
80+
81+
}
82+
83+
@Override
84+
public void done() {
85+
86+
}
87+
88+
@Override
89+
public void beginTask(String name, int totalWork) {
90+
setTaskName(name);
91+
}
92+
};
93+
project.build(IncrementalProjectBuilder.CLEAN_BUILD, debugMonitor);
94+
project.build(IncrementalProjectBuilder.FULL_BUILD, debugMonitor);
95+
for (IMarker marker : project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)) {
96+
result.addMarker(marker);
97+
debug(marker.toString());
98+
}
99+
ResourcesPlugin.getWorkspace().save(true, new NullProgressMonitor());
100+
return result;
101+
}
102+
103+
static void disableAutoBuild() throws CoreException {
104+
IWorkspace workspace = ResourcesPlugin.getWorkspace();
105+
IWorkspaceDescription desc = workspace.getDescription();
106+
desc.setAutoBuilding(false);
107+
workspace.setDescription(desc);
108+
}
109+
110+
private void deleteAllProjects() throws CoreException {
111+
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
112+
project.delete(IResource.NEVER_DELETE_PROJECT_CONTENT | IResource.FORCE, new NullProgressMonitor());
113+
}
114+
}
115+
116+
private IProject importProject() throws CoreException, IOException {
117+
IPath projectPath = IPath.fromOSString(baseDir);
118+
IPath projectDescriptionFile = projectPath.append(IProjectDescription.DESCRIPTION_FILE_NAME);
119+
IProjectDescription projectDescription = ResourcesPlugin.getWorkspace()
120+
.loadProjectDescription(projectDescriptionFile);
121+
projectDescription.setLocation(projectPath);
122+
// projectDescription.setBuildSpec(new ICommand[0]);
123+
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectDescription.getName());
124+
project.create(projectDescription, new NullProgressMonitor());
125+
project.open(new NullProgressMonitor());
126+
return project;
127+
}
128+
129+
private void debug(String string) {
130+
if (debug) {
131+
System.out.println(string);
132+
}
133+
}
134+
135+
static String pathAsString(Path path) {
136+
if (path != null) {
137+
return path.toAbsolutePath().toString();
138+
}
139+
return null;
140+
}
141+
142+
}

0 commit comments

Comments
 (0)