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 features / dir bundles / install bundle in EclipseApplication #3060

Merged
merged 1 commit into from
Nov 22, 2023
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 @@ -27,8 +27,10 @@
import java.util.ServiceLoader;
import java.util.Set;
import java.util.function.Predicate;
import java.util.jar.JarFile;

import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.archiver.zip.ZipUnArchiver;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
Expand Down Expand Up @@ -130,12 +132,25 @@ private List<Path> resolveBundles(P2Resolver resolver) {
*/
public synchronized void addBundle(String bundleSymbolicName) {
try {
resolver.addDependency(ArtifactType.TYPE_INSTALLABLE_UNIT, bundleSymbolicName, "0.0.0");
resolver.addDependency(ArtifactType.TYPE_ECLIPSE_PLUGIN, bundleSymbolicName, "0.0.0");
needResolve = true;
} catch (IllegalArtifactReferenceException e) {
throw new TargetPlatformConfigurationException("Can't add API tools requirement", e);
}
}

/**
* Add a feature to the application
*
* @param featureId
*/
public synchronized void addFeature(String featureId) {
try {
resolver.addDependency(ArtifactType.TYPE_ECLIPSE_FEATURE, featureId, "0.0.0");
needResolve = true;
} catch (IllegalArtifactReferenceException e) {
throw new TargetPlatformConfigurationException("Can't add API tools requirement", e);
}
}

/**
Expand Down Expand Up @@ -205,6 +220,17 @@ public <T> EclipseFramework startFramework(EclipseWorkspace<T> workspace, List<S
//not installed yet...
if (Files.isDirectory(bundleFile)) {
bundle = systemBundleContext.installBundle(location);
} else if (isDirectoryBundly(bundleFile)) {
Path explodePath = workspace.getWorkDir().resolve("exploded").resolve(bundleFile.getFileName());
try {
Files.createDirectories(explodePath);
ZipUnArchiver unArchiver = new ZipUnArchiver(bundleFile.toFile());
unArchiver.setDestDirectory(explodePath.toFile());
unArchiver.extract();
} catch (IOException e) {
throw new BundleException("can't explode bundle " + bundleFile, e);
}
bundle = systemBundleContext.installBundle(explodePath.toUri().toASCIIString());
} else {
try (InputStream stream = Files.newInputStream(bundleFile)) {
bundle = systemBundleContext.installBundle(location, stream);
Expand All @@ -222,6 +248,14 @@ public <T> EclipseFramework startFramework(EclipseWorkspace<T> workspace, List<S
return new EclipseFramework(framework, configuration, this, connector);
}

private boolean isDirectoryBundly(Path bundleFile) {
try (JarFile jarFile = new JarFile(bundleFile.toFile())) {
return "dir".equals(jarFile.getManifest().getMainAttributes().getValue("Eclipse-BundleShape"));
} catch (IOException e1) {
}
return false;
}

private void setupLogging(BundleContext bundleContext) {
LogListener logListener = new LogListener() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void addBundlesAndFeatures(Bundles bundles, Features features, EclipseAp
application.addBundle(bsn);
}
for (String feature : features.features()) {
//TODO application.addFeature(feature);
application.addFeature(feature);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
Expand Down Expand Up @@ -191,4 +193,10 @@ public boolean hasBundle(String bsn) {
return false;
}

public Bundle install(File file) throws IOException, BundleException {
try (FileInputStream stream = new FileInputStream(file)) {
return framework.getBundleContext().installBundle(file.getAbsolutePath(), stream);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public class EclipseBuildMojo extends AbstractMojo {
@Parameter
private List<String> bundles;

@Parameter
private List<String> features;

@Parameter(property = "project", readonly = true)
private MavenProject project;

Expand All @@ -101,7 +104,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
EclipseApplication application;
//TODO configureable by parameters!
Bundles bundles = new Bundles(getBundles());
Features features = new Features(Set.of());
Features features = new Features(getFeatures());
if (local) {
TargetPlatform targetPlatform = projectManager.getTargetPlatform(project).orElseThrow(
() -> new MojoFailureException("Can't get target platform for project " + project.getId()));
Expand Down Expand Up @@ -145,8 +148,16 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

private Set<String> getFeatures() {
Set<String> set = new HashSet<>();
if (features != null) {
set.addAll(features);
}
return set;
}

private Set<String> getBundles() {
HashSet<String> set = new HashSet<>();
Set<String> set = new HashSet<>();
set.add("org.eclipse.core.resources");
set.add("org.eclipse.core.runtime");
set.add("org.eclipse.core.jobs");
Expand Down