Skip to content

Commit

Permalink
Add support for p2.inf in eclipse-repository packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jun 24, 2023
1 parent e49d7ff commit 1e22e5b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
import java.util.Locale;
import java.util.Properties;

import org.eclipse.core.runtime.Path;
import org.eclipse.equinox.internal.p2.updatesite.CategoryXMLAction;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
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.publisher.AdviceFileAdvice;
import org.eclipse.equinox.p2.publisher.IPublisherAction;
import org.eclipse.equinox.p2.publisher.actions.JREAction;
import org.eclipse.tycho.ExecutionEnvironment;
Expand Down Expand Up @@ -63,7 +68,19 @@ public Collection<DependencySeed> publishCategories(File categoryDefinition)
*/
Collection<IInstallableUnit> allIUs = publisherRunner.executeAction(categoryXMLAction,
publishingRepository.getMetadataRepository(), publishingRepository.getArtifactRepository());
// TODO introduce type "eclipse-category"?
File p2inf = new File(categoryDefinition.getParentFile(), "p2.inf");
if (p2inf.isFile()) {
AdviceFileAdvice advice = new AdviceFileAdvice("category.xml", Version.parseVersion("1.0"),
new Path(p2inf.getParentFile().getAbsolutePath()), new Path("p2.inf"));
if (advice.containsAdvice()) {
InstallableUnitDescription[] descriptions = advice.getAdditionalInstallableUnitDescriptions(null);
if (descriptions != null && descriptions.length > 0) {
for (InstallableUnitDescription desc : descriptions) {
allIUs.add(MetadataFactory.createInstallableUnit(desc));
}
}
}
}
return toSeeds(null, allIUs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,24 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.publisher.eclipse.FeatureParser;
import org.eclipse.equinox.internal.p2.publisher.eclipse.IProductDescriptor;
import org.eclipse.equinox.internal.p2.updatesite.CategoryParser;
import org.eclipse.equinox.internal.p2.updatesite.SiteModel;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
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.publisher.AbstractPublisherAction;
import org.eclipse.equinox.p2.publisher.AdviceFileAdvice;
import org.eclipse.equinox.p2.publisher.IPublisherAction;
import org.eclipse.equinox.p2.publisher.IPublisherAdvice;
import org.eclipse.equinox.p2.publisher.IPublisherInfo;
import org.eclipse.equinox.p2.publisher.IPublisherResult;
import org.eclipse.equinox.p2.publisher.PublisherInfo;
import org.eclipse.equinox.p2.publisher.actions.IFeatureRootAdvice;
import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction;
Expand Down Expand Up @@ -289,6 +299,31 @@ protected List<IPublisherAction> getPublisherActions(IArtifactFacade artifact, L
throw new RuntimeException("Unable to read category File", e);
}
}
File p2inf = new File(location, "p2.inf");
if (p2inf.isFile()) {
AdviceFileAdvice advice = new AdviceFileAdvice(artifact.getArtifactId(), Version.parseVersion("1.0"),
new Path(location.getAbsolutePath()), new Path("p2.inf"));
if (advice.containsAdvice()) {
actions.add(new AbstractPublisherAction() {

@Override
public IStatus perform(IPublisherInfo publisherInfo, IPublisherResult results,
IProgressMonitor monitor) {
InstallableUnitDescription[] descriptions = advice
.getAdditionalInstallableUnitDescriptions(null);
if (descriptions != null && descriptions.length > 0) {
for (InstallableUnitDescription desc : descriptions) {
results.addIU(MetadataFactory.createInstallableUnit(desc),
IPublisherResult.NON_ROOT);
}
}
// publisherInfo.addAdvice(advice);
return Status.OK_STATUS;
}

});
}
}
} else if (PackagingType.TYPE_P2_SITE.equals(packaging)) {
//nothing to do at the moment...
} else if (PackagingType.TYPE_P2_IU.equals(packaging)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.tycho.BuildDirectory;
import org.eclipse.tycho.PackagingType;
Expand Down Expand Up @@ -90,12 +90,21 @@ private File prepareBuildCategory(Category category, BuildDirectory buildFolder)
buildFolder.getLocation().mkdirs();
Category.write(category, ret);
copySiteI18nFiles(buildFolder);
copyP2Inf(buildFolder);
return ret;
} catch (IOException e) {
throw new MojoExecutionException("I/O exception while writing category definition to disk", e);
}
}

private void copyP2Inf(BuildDirectory buildFolder) throws IOException {
File p2inf = new File(getProject().getBasedir(), "p2.inf");
if (p2inf.isFile()) {
FileUtils.copyFile(p2inf, buildFolder.getChild(p2inf.getName()));
}

}

private void copySiteI18nFiles(BuildDirectory buildFolder) throws IOException {
File[] i18nFiles = getProject().getBasedir().listFiles((FileFilter) file -> {
String fileName = file.getName();
Expand Down

0 comments on commit 1e22e5b

Please sign in to comment.