@Override public void generate(final GenerationContext context) throws Exception { final String id = getString(context.getArtifactInformation().getMetaData(), ID, "id"); final String version = getString(context.getArtifactInformation().getMetaData(), ID, "version"); final Path tmp = Files.createTempFile("p2-feat-", ".jar"); try { try (final ZipOutputStream jar = new ZipOutputStream(new FileOutputStream(tmp.toFile()))) { final ZipEntry ze = new ZipEntry("feature.xml"); jar.putNextEntry(ze); createFeatureXml(jar, context.getArtifactInformation().getMetaData(), context); } final Map<MetaKey, String> providedMetaData = new HashMap<>(); try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(tmp.toFile()))) { context.createVirtualArtifact( String.format("%s-%s.jar", id, version), is, providedMetaData); } } finally { Files.deleteIfExists(tmp); } }
@Override public void generate(final GenerationContext context) throws Exception { Document doc; try (BufferedInputStream is = new BufferedInputStream(Files.newInputStream(context.getFile()))) { doc = this.xml.parse(is); } final CategoryDefinition def = CategoryXmlParser.parse(doc); final String baseName = context.getArtifactInformation().getName(); final Map<String, Set<ArtifactInformation>> map = new HashMap<>(); for (final ArtifactInformation ai : context.getChannelArtifacts()) { if (Helper.isBundle(ai.getMetaData())) { final String id = ai.getMetaData().get(MK_OSGI_NAME); final Set<String> cats = def.getBundles().get(id); if (cats != null) { for (final String cat : cats) { addMap(map, cat, ai); } } } if (Helper.isFeature(ai.getMetaData())) { final String id = ai.getMetaData().get(MK_OSGI_NAME); final Set<String> cats = def.getFeatures().get(id); if (cats != null) { for (final String cat : cats) { addMap(map, cat, ai); } } } } context.createVirtualArtifact( baseName + "-p2metadata.xml", out -> { Helper.createFragmentFile( out, (units) -> { for (final Category cat : def.getCategories()) { Helper.createCategoryUnit( units, cat.getId(), cat.getLabel(), cat.getDescription(), Helper.makeDefaultVersion(), (unit) -> { final Element reqs = XmlHelper.addElement(unit, "requires"); final Set<String> ctx = new HashSet<>(); final Set<ArtifactInformation> list = map.get(cat.getId()); if (list != null) { for (final ArtifactInformation ai : list) { if (Helper.isFeature(ai.getMetaData())) { Helper.addFeatureRequirement(ctx, reqs, ai); } else if (Helper.isBundle(ai.getMetaData())) { Helper.addBundleRequirement(ctx, reqs, ai); } } } XmlHelper.fixSize(reqs); }); } }); }, null); }