Search in sources :

Example 1 with AttributeContext

use of org.haiku.pkg.AttributeContext in project haikudepotserver by haiku.

the class PkgImportServiceImpl method populateIconFromPayload.

private void populateIconFromPayload(ObjectContext objectContext, PkgVersion persistedPkgVersion, HpkgFileExtractor hpkgFileExtractor) {
    AttributeContext context = hpkgFileExtractor.getTocContext();
    List<Attribute> iconAttrs = HpkgHelper.findIconAttributesFromExecutableDirEntries(context, hpkgFileExtractor.getToc());
    switch(iconAttrs.size()) {
        case 0:
            LOGGER.info("package [{}] version [{}] has no icons", persistedPkgVersion.getPkg(), persistedPkgVersion);
            break;
        case 1:
            populateIconFromPayload(objectContext, persistedPkgVersion, context, Iterables.getFirst(iconAttrs, null));
            break;
        default:
            LOGGER.info("package [{}] version [{}] has {} icons --> ambiguous so will not load any", persistedPkgVersion.getPkg(), persistedPkgVersion, iconAttrs.size());
            break;
    }
}
Also used : AttributeContext(org.haiku.pkg.AttributeContext) Attribute(org.haiku.pkg.model.Attribute)

Example 2 with AttributeContext

use of org.haiku.pkg.AttributeContext in project haikudepotserver by haiku.

the class HpkgHelperTest method testFindIconAttributesFromAppExecutableDirEntries.

@Test
public void testFindIconAttributesFromAppExecutableDirEntries() throws Exception {
    // GIVEN
    File file = prepareTestFile(RESOURCE_TEST);
    HpkgFileExtractor fileExtractor = new HpkgFileExtractor(file);
    AttributeContext tocContext = fileExtractor.getTocContext();
    // WHEN
    List<Attribute> attributes = HpkgHelper.findIconAttributesFromExecutableDirEntries(tocContext, fileExtractor.getToc());
    // THEN
    Assertions.assertThat(attributes).hasSize(1);
    Attribute iconA = Iterables.getOnlyElement(attributes);
    Attribute iconDataA = iconA.getChildAttribute(AttributeId.DATA);
    ByteSource byteSource = (ByteSource) iconDataA.getValue(tocContext);
    byte[] data = byteSource.read();
    Assertions.assertThat(data).hasSize(544);
    assertIsHvif(data);
}
Also used : AttributeContext(org.haiku.pkg.AttributeContext) Attribute(org.haiku.pkg.model.Attribute) ByteSource(com.google.common.io.ByteSource) HpkgFileExtractor(org.haiku.pkg.HpkgFileExtractor) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeContext (org.haiku.pkg.AttributeContext)2 Attribute (org.haiku.pkg.model.Attribute)2 ByteSource (com.google.common.io.ByteSource)1 File (java.io.File)1 HpkgFileExtractor (org.haiku.pkg.HpkgFileExtractor)1 Test (org.junit.jupiter.api.Test)1