Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tycho-4.0.x] Support specification of an application to run #4639

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.launch.Framework;
import org.osgi.util.tracker.ServiceTracker;

public class EclipseFramework implements AutoCloseable {

Expand Down Expand Up @@ -84,6 +85,25 @@ public void start() throws Exception {
}
}

public boolean waitForApplicationStart(long timeout) {
String[] args = configuration.getNonFrameworkArgs();
for (String arg : args) {
if (EclipseApplication.ARG_APPLICATION.equals(arg)) {
ServiceTracker<ApplicationLauncher, Object> tracker = new ServiceTracker<>(framework.getBundleContext(),
ApplicationLauncher.class, null);
tracker.open(true);
try {
return tracker.waitForService(timeout) != null;
} catch (InterruptedException e) {
return false;
} finally {
tracker.close();
}
}
}
return true;
}

private int launchApplication(BundleContext systemBundleContext, EquinoxConfiguration configuration)
throws Exception {
EclipseAppLauncher appLauncher = new EclipseAppLauncher(systemBundleContext, false, true, null, configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.Job;

/**
* Abstract class for performing a build and producing a result
Expand All @@ -42,7 +43,7 @@ public final Result call() throws Exception {
deleteAllProjects();
IProject project = importProject();
project.build(IncrementalProjectBuilder.CLEAN_BUILD, this);
project.build(IncrementalProjectBuilder.FULL_BUILD, this);
buildProject(project);
Result result = createResult(project);
for (IMarker marker : project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)) {
result.addMarker(marker);
Expand All @@ -52,6 +53,13 @@ public final Result call() throws Exception {
return result;
}

protected void buildProject(IProject project) throws CoreException {
project.build(IncrementalProjectBuilder.FULL_BUILD, this);
while (!Job.getJobManager().isIdle()) {
Thread.yield();
}
}

protected abstract Result createResult(IProject project) throws Exception;

static void disableAutoBuild() throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -80,6 +81,8 @@ public abstract class AbstractEclipseBuildMojo<Result extends EclipseBuildResult
@Parameter(defaultValue = "false")
private boolean failOnResolutionError;

@Parameter
private String application;
/**
* Controls if the local target platform of the project should be used to
* resolve the eclipse application
Expand Down Expand Up @@ -137,11 +140,35 @@ public final void execute() throws MojoExecutionException, MojoFailureException
} else {
application = eclipseApplicationManager.getApplication(eclipseRepository, bundles, features, getName());
}
List<String> arguments;
String applicationName = this.application;
boolean useApplication = applicationName != null;
if (useApplication) {
arguments = List.of(EclipseApplication.ARG_APPLICATION, applicationName);
} else {
arguments = List.of();
}
try (EclipseFramework framework = application.startFramework(workspaceManager
.getWorkspace(EclipseApplicationManager.getRepository(eclipseRepository).getURL(), this), List.of())) {
.getWorkspace(EclipseApplicationManager.getRepository(eclipseRepository).getURL(), this), arguments)) {
if (debug) {
framework.printState();
}
if (useApplication) {
Thread thread = new Thread(new Runnable() {

@Override
public void run() {
try {
framework.start();
} catch (Exception e) {
getLog().error("Running application " + applicationName + " failed", e);
}
}
});
thread.setName(getName() + " Application Thread");
thread.start();
framework.waitForApplicationStart(TimeUnit.SECONDS.toMillis(30));
}
if (hasPDENature(eclipseProject)) {
if (framework.hasBundle(Bundles.BUNDLE_PDE_CORE)) {
framework.execute(new SetTargetPlatform(projectDependencies, debug));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.pde.core.target.ITargetDefinition;
import org.eclipse.pde.core.target.ITargetLocation;
import org.eclipse.pde.core.target.ITargetPlatformService;
import org.eclipse.pde.core.target.LoadTargetDefinitionJob;
import org.eclipse.pde.core.target.TargetBundle;
import org.eclipse.pde.internal.core.PluginModelManager;
import org.eclipse.pde.internal.core.target.TargetPlatformService;

public class SetTargetPlatform implements Callable<Serializable>, Serializable {
Expand Down Expand Up @@ -64,6 +66,7 @@ public Serializable call() throws Exception {
Job job = new LoadTargetDefinitionJob(target);
job.schedule();
job.join();
Job.getJobManager().join(PluginModelManager.class, new NullProgressMonitor());
return null;
}

Expand Down
Loading