use of org.haiku.pkg.model.Pkg in project haikudepotserver by haiku.
the class PkgFactoryTest method testCreatePackage.
@Test
public void testCreatePackage() {
Attribute attribute = createTestPackageAttributes();
PkgFactory pkgFactory = new PkgFactory();
// it is ok that this is empty because the factory should not need to reference the heap again; its all inline
// and we are not testing the heap here.
AttributeContext attributeContext = new AttributeContext();
Pkg pkg = pkgFactory.createPackage(attributeContext, attribute);
// now do some checks.
assertThat(pkg.getArchitecture()).isEqualTo(PkgArchitecture.X86);
assertThat(pkg.getName()).isEqualTo("testpkg");
assertThat(pkg.getVendor()).isEqualTo("Test Vendor");
assertThat(pkg.getSummary()).isEqualTo("This is a test package summary");
assertThat(pkg.getDescription()).isEqualTo("This is a test package description");
assertThat(pkg.getHomePageUrl().getUrl()).isEqualTo("http://www.haiku-os.org");
assertThat(pkg.getHomePageUrl().getUrlType()).isEqualTo(PkgUrlType.HOMEPAGE);
assertThat(pkg.getVersion().getMajor()).isEqualTo("6");
assertThat(pkg.getVersion().getMinor()).isEqualTo("32");
assertThat(pkg.getVersion().getMicro()).isEqualTo("9");
assertThat(pkg.getVersion().getPreRelease()).isEqualTo("beta");
assertThat(pkg.getVersion().getRevision()).isEqualTo(8);
assertThat(pkg.getCopyrights().stream().anyMatch(x -> x.equals("Some copyright A"))).isTrue();
assertThat(pkg.getLicenses().stream().anyMatch(x -> x.equals("Some license A"))).isTrue();
assertThat(pkg.getLicenses().stream().anyMatch(x -> x.equals("Some license B"))).isTrue();
}
use of org.haiku.pkg.model.Pkg in project haikudepotserver by haiku.
the class RepositoryHpkrIngressJobRunner method runImportHpkrForRepositorySource.
private void runImportHpkrForRepositorySource(ObjectContext mainContext, RepositorySource repositorySource) {
URL url = repositorySource.tryGetInternalFacingDownloadHpkrURL().orElseThrow(() -> new RuntimeException("unable to import for [" + repositorySource + "] as there is no download url able to be derived."));
// now shift the URL's data into a temporary file and then process it.
File temporaryFile = null;
try {
temporaryFile = File.createTempFile(repositorySource.getCode() + "__import", ".hpkr");
LOGGER.info("will copy repository hpkr [{}] ({}) to temporary file", repositorySource, url.toString());
FileHelper.streamUrlDataToFile(url, temporaryFile, TIMEOUT_REPOSITORY_SOURCE_FETCH);
LOGGER.info("did copy {} bytes for repository hpkr [{}] ({}) to temporary file", temporaryFile.length(), repositorySource, url);
HpkrFileExtractor fileExtractor = new HpkrFileExtractor(temporaryFile);
long startTimeMs = System.currentTimeMillis();
LOGGER.info("will process data for repository hpkr {}", repositorySource.getCode());
// import any packages that are in the repository.
Set<String> repositoryImportPkgNames = Sets.newHashSet();
PkgIterator pkgIterator = new PkgIterator(fileExtractor.getPackageAttributesIterator());
while (pkgIterator.hasNext()) {
ObjectContext pkgImportContext = serverRuntime.newContext();
Pkg pkg = pkgIterator.next();
repositoryImportPkgNames.add(pkg.getName());
try {
pkgImportService.importFrom(pkgImportContext, repositorySource.getObjectId(), pkg, shouldPopulateFromPayload);
pkgImportContext.commitChanges();
} catch (Throwable th) {
throw new RepositoryHpkrIngressException("unable to store package [" + pkg + "]", th);
}
}
// [apl 6.aug.2014] #5
// Packages may be removed from a repository. In this case there is no trigger to indicate that the
// package version should be removed. Check all of the packages that have an active version in this
// repository and then if the package simply doesn't exist in that repository any more, mark all of
// those versions are inactive.
pkgService.fetchPkgNamesWithAnyPkgVersionAssociatedWithRepositorySource(mainContext, repositorySource).forEach((persistedPkgName) -> {
if (!repositoryImportPkgNames.contains(persistedPkgName)) {
ObjectContext removalContext = serverRuntime.newContext();
RepositorySource removalRepositorySource = RepositorySource.get(removalContext, repositorySource.getObjectId());
int changes = pkgService.deactivatePkgVersionsForPkgAssociatedWithRepositorySource(removalContext, org.haiku.haikudepotserver.dataobjects.Pkg.getByName(removalContext, persistedPkgName), removalRepositorySource);
if (changes > 0) {
removalContext.commitChanges();
LOGGER.info("did remove all versions of package {} from repository source {} because this package is no longer in the repository", persistedPkgName, repositorySource);
}
}
});
LOGGER.info("did process data for repository hpkr {} in {}ms", repositorySource, System.currentTimeMillis() - startTimeMs);
} catch (Throwable th) {
throw new RuntimeException("a problem has arisen processing a repository file for repository hpkr " + repositorySource + " from url '" + url.toString() + "'", th);
} finally {
if (null != temporaryFile && temporaryFile.exists()) {
if (!temporaryFile.delete()) {
LOGGER.error("unable to delete the file; {}" + temporaryFile.getAbsolutePath());
}
}
}
}
use of org.haiku.pkg.model.Pkg in project haikudepotserver by haiku.
the class PkgImportServiceImplIT method testImport_payloadData.
/**
* <P>During the import process, it is possible that the system is able to check the length of the
* package. This test will check that this mechanism is working.</P>
*/
@Test
public void testImport_payloadData() throws Exception {
File repositoryDirectory = null;
int expectedPayloadLength;
try {
// create the repository
integrationTestSupportService.createStandardTestData();
Pkg inputPackage = createPkg("3");
// setup a test repository
{
ObjectContext context = serverRuntime.newContext();
RepositorySource repositorySource = RepositorySource.tryGetByCode(context, "testreposrc_xyz").get();
repositoryDirectory = new File(repositorySource.tryGetPackagesBaseURL(ExposureType.INTERNAL_FACING).get().getPath());
if (!repositoryDirectory.mkdirs()) {
throw new IllegalStateException("unable to create the on-disk repository");
}
File fileF = new File(repositoryDirectory, "testpkg-1.3.3~4-5-x86_64.hpkg");
byte[] payload = Resources.toByteArray(Resources.getResource(RESOURCE_TEST));
Files.write(payload, fileF);
expectedPayloadLength = payload.length;
}
// now load the next package version in
{
ObjectContext context = serverRuntime.newContext();
RepositorySource repositorySource = RepositorySource.tryGetByCode(context, "testreposrc_xyz").get();
// ---------------------------------
pkgImportService.importFrom(context, repositorySource.getObjectId(), inputPackage, // <--- NOTE
true);
// ---------------------------------
context.commitChanges();
}
// check the length on that package is there and is correct and that the
// package icon is loaded in.
{
ObjectContext context = serverRuntime.newContext();
org.haiku.haikudepotserver.dataobjects.Pkg pkg = org.haiku.haikudepotserver.dataobjects.Pkg.getByName(context, "testpkg");
org.haiku.haikudepotserver.dataobjects.PkgVersion pkgVersion = pkgService.getLatestPkgVersionForPkg(context, pkg, Repository.tryGetByCode(context, "testrepo").get(), Collections.singletonList(Architecture.tryGetByCode(context, "x86_64").get())).get();
Assertions.assertThat(pkgVersion.getPayloadLength()).isEqualTo(expectedPayloadLength);
List<PkgIcon> pkgIcons = pkg.getPkgSupplement().getPkgIcons();
Assertions.assertThat(pkgIcons).hasSize(1);
PkgIcon pkgIcon = Iterables.getOnlyElement(pkgIcons);
byte[] actualIconData = pkgIcon.getPkgIconImage().getData();
Assertions.assertThat(actualIconData).hasSize(544);
}
} finally {
if (null != repositoryDirectory) {
FileHelper.delete(repositoryDirectory);
}
}
}
use of org.haiku.pkg.model.Pkg in project haikudepotserver by haiku.
the class PkgImportServiceImplIT method testImport_versionRegressionDeactivatesNewerVersions.
/**
* <p>If there is a series of packages and suddenly there is an older version come in then the future versions
* should be deactivated.</p>
*/
@Test
public void testImport_versionRegressionDeactivatesNewerVersions() {
integrationTestSupportService.createStandardTestData();
int highestMinor = 6;
{
ObjectContext context = serverRuntime.newContext();
org.haiku.haikudepotserver.dataobjects.Pkg pkg = integrationTestSupportService.createPkg(context, "pkgx");
for (int i = 1; i <= 6; i++) {
org.haiku.haikudepotserver.dataobjects.PkgVersion pkgVersion = context.newObject(org.haiku.haikudepotserver.dataobjects.PkgVersion.class);
pkgVersion.setPkg(pkg);
pkgVersion.setIsLatest(i == highestMinor);
pkgVersion.setArchitecture(org.haiku.haikudepotserver.dataobjects.Architecture.getByCode(context, Architecture.CODE_X86_64));
pkgVersion.setMajor("1");
pkgVersion.setMinor(Integer.toString(i));
pkgVersion.setRepositorySource(RepositorySource.getByCode(context, "testreposrc_xyz"));
}
context.commitChanges();
}
// now there are a string of pkg versions in place, import an older one.
Pkg inputPackage = new Pkg("pkgx", // <-- version in middle of pkg versions
new PkgVersion("1", "4", null, null, null), PkgArchitecture.X86_64, null, Collections.emptyList(), Collections.emptyList(), "test-summary-en", "test-description-en", null);
{
ObjectContext context = serverRuntime.newContext();
ObjectId repositorySourceObjectId = RepositorySource.getByCode(context, "testreposrc_xyz").getObjectId();
// ---------------------------------
pkgImportService.importFrom(context, repositorySourceObjectId, inputPackage, false);
// ---------------------------------
context.commitChanges();
}
// now check to see that the right outcomes have been achieved.
{
ObjectContext context = serverRuntime.newContext();
List<org.haiku.haikudepotserver.dataobjects.PkgVersion> pkgVersions = org.haiku.haikudepotserver.dataobjects.PkgVersion.getForPkg(context, org.haiku.haikudepotserver.dataobjects.Pkg.getByName(context, "pkgx"), true);
Assertions.assertThat(pkgVersions.size()).isEqualTo(6);
for (org.haiku.haikudepotserver.dataobjects.PkgVersion pkgVersion : pkgVersions) {
switch(Integer.parseInt(pkgVersion.getMinor())) {
case 1:
case 2:
case 3:
Assertions.assertThat(pkgVersion.getActive()).isTrue();
Assertions.assertThat(pkgVersion.getIsLatest()).isFalse();
break;
case 4:
Assertions.assertThat(pkgVersion.getActive()).isTrue();
Assertions.assertThat(pkgVersion.getIsLatest()).isTrue();
break;
case 5:
case 6:
Assertions.assertThat(pkgVersion.getActive()).isFalse();
Assertions.assertThat(pkgVersion.getIsLatest()).isFalse();
break;
default:
throw new IllegalStateException("unknown pkg version; " + pkgVersion.toVersionCoordinates().toString());
}
}
}
}
use of org.haiku.pkg.model.Pkg in project haikudepotserver by haiku.
the class PkgImportServiceImplIT method testImport_develPkgHandling.
/**
* <p>When a "_devel" package is imported there is a special behaviour that the localization and the
* icons are copied from the main package over to the "_devel" package.</p>
*/
@Test
public void testImport_develPkgHandling() throws Exception {
ObjectId respositorySourceObjectId;
{
integrationTestSupportService.createStandardTestData();
ObjectContext context = serverRuntime.newContext();
RepositorySource repositorySource = RepositorySource.tryGetByCode(context, "testreposrc_xyz").get();
respositorySourceObjectId = repositorySource.getObjectId();
}
// setup the base package.
{
Pkg importPkg = createPkg("2");
{
ObjectContext importObjectContext = serverRuntime.newContext();
pkgImportService.importFrom(importObjectContext, respositorySourceObjectId, importPkg, false);
importObjectContext.commitChanges();
}
// now add some localization to the imported package.
{
ObjectContext setupObjectContext = serverRuntime.newContext();
org.haiku.haikudepotserver.dataobjects.Pkg persistedPkg = org.haiku.haikudepotserver.dataobjects.Pkg.getByName(setupObjectContext, importPkg.getName());
setupObjectContext.commitChanges();
pkgLocalizationService.updatePkgLocalization(setupObjectContext, persistedPkg.getPkgSupplement(), NaturalLanguage.getByCode(setupObjectContext, NaturalLanguage.CODE_GERMAN), "title_kingston_black", "summary_kingston_black", "description_kingston_black");
setupObjectContext.commitChanges();
try (InputStream inputStream = Resources.asByteSource(Resources.getResource("sample-32x32.png")).openStream()) {
pkgIconService.storePkgIconImage(inputStream, MediaType.getByCode(setupObjectContext, com.google.common.net.MediaType.PNG.toString()), 32, setupObjectContext, persistedPkg.getPkgSupplement());
}
setupObjectContext.commitChanges();
}
}
// setup the devel package.
Pkg importDevelPkg = new Pkg("testpkg" + PkgServiceImpl.SUFFIX_PKG_DEVELOPMENT, new PkgVersion("1", "2", "3", "4", 5), PkgArchitecture.X86_64, null, Collections.emptyList(), Collections.emptyList(), "test-summary-en", "test-description-en", null);
// ---------------------------------
{
ObjectContext importObjectContext = serverRuntime.newContext();
pkgImportService.importFrom(importObjectContext, respositorySourceObjectId, importDevelPkg, false);
importObjectContext.commitChanges();
}
// ---------------------------------
// check it has the icon and the localization.
{
ObjectContext context = serverRuntime.newContext();
org.haiku.haikudepotserver.dataobjects.Pkg persistedDevelPkg = org.haiku.haikudepotserver.dataobjects.Pkg.getByName(context, importDevelPkg.getName());
PkgSupplement persistedDevelPkgSupplement = persistedDevelPkg.getPkgSupplement();
Assertions.assertThat(persistedDevelPkgSupplement.getPkgIcons().size()).isEqualTo(1);
Assertions.assertThat(persistedDevelPkgSupplement.getPkgIcons().get(0).getSize()).isEqualTo(32);
PkgLocalization pkgLocalization = persistedDevelPkgSupplement.getPkgLocalization(NaturalLanguage.CODE_GERMAN).get();
Assertions.assertThat(pkgLocalization.getTitle()).isEqualTo("title_kingston_black");
Assertions.assertThat(pkgLocalization.getSummary()).isEqualTo("summary_kingston_black");
Assertions.assertThat(pkgLocalization.getDescription()).isEqualTo("description_kingston_black");
}
}
Aggregations