PackageOperationInstall implements PackageOperation { @Override public void execute(PackageOperationContext context, ProgressReceiver progressReceiver) throws IOException { progressReceiver.progress("Installing package '" + pkg.getName() + "'"); final Path localPackageFile = context.getLocalPackageRepository().getPackage(pkg); if (findAREntry("data.tar.gz", localPackageFile, (entry, ais) -> { final TarArchiveInputStream tis = new TarArchiveInputStream(new GZIPInputStream(ais)); TarArchiveEntry t; final List<PackageInstalledContent> installedContents = new ArrayList<>(); while ((t = tis.getNextTarEntry()) != null) { final PackageInstalledContent installedContent = installFile(tis, t, context); if (installedContent != null) installedContents.add(installedContent); } int sequenceNumber = 0; for (PackageInstalledContent e : installedContents) { e.setPackage(pkg); e.setSequence(sequenceNumber++); } pkg.setInstalled(true); context.getDatabase().getPackageRepository().save(pkg); context.getDatabase().getInstalledContentRepository().saveAll(installedContents); }) == 0) { throw new IOException("Illegal package format. Missing data.tar.gz"); } } PackageOperationInstall(Package pkg); @Override Package getPackage(); @Override void execute(PackageOperationContext context, ProgressReceiver progressReceiver);  }
@Test public void testInstallPackage() throws Exception { Package pkg = createPackage("foo", "2.0-1", "foo_2.0-1_i386.deb"); final Path testdir = TestDirectoryProvider.get(); Files.createDirectories(testdir); final DefaultLocalPackageRepository repo = new DefaultLocalPackageRepository(testdir.resolve("archive")); repo.addPackage(pkg, targetPath -> Files.copy(getClass().getResourceAsStream("/test-repository/foo_2.0-1_i386.deb"), targetPath)); final PackageOperationInstall op = new PackageOperationInstall(pkg); final Path installDir = testdir.resolve("install"); op.execute(new DefaultPackageOperationContext(repo, new PackageManagerDatabase(null, packageRepository, null, null, installedContentRepository), null, installDir, pkg), new NoopProgressReceiver()); assertDirectory(installDir, "schema"); assertDirectory(installDir, "schema/application"); assertFile(installDir, "schema/application/foo-tiny.xml.sample", "e5b0268ae229188d1b434fe34879aa645f1d09ab"); assertFile(installDir, "schema/application/foo.xml", "58091c6fbbf30c7e10b971865ab4413973583bb3"); assertDirectory(installDir, "sfs"); assertDirectory(installDir, "sfs/package"); assertFile(installDir, "sfs/package/foo.sfs", "49c266b761aa645ad47e22a75da60e992654b427"); assertDirectory(installDir, "version"); assertFile(installDir, "version/version.txt~", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); assertFile(installDir, "version/foo-version.txt", "5859d094ddc1848ef3d7fc6ff1d02d75d6ec1d95"); final List<PackageInstalledContent> expected = Arrays.asList( installedDirectory(pkg, 0, "schema"), installedDirectory(pkg, 1, "schema/application"), installedFile(pkg, 2, "schema/application/foo-tiny.xml.sample", "e5b0268ae229188d1b434fe34879aa645f1d09ab"), installedFile(pkg, 3, "schema/application/foo.xml", "58091c6fbbf30c7e10b971865ab4413973583bb3"), installedDirectory(pkg, 4, "sfs"), installedDirectory(pkg, 5, "sfs/package"), installedFile(pkg, 6, "sfs/package/foo.sfs", "49c266b761aa645ad47e22a75da60e992654b427"), installedDirectory(pkg, 7, "version"), installedFile(pkg, 8, "version/version.txt~", "da39a3ee5e6b4b0d3255bfef95601890afd80709"), installedFile(pkg, 9, "version/foo-version.txt", "5859d094ddc1848ef3d7fc6ff1d02d75d6ec1d95") ); Mockito.verify(installedContentRepository).saveAll(expected); }