added support for zstd packages
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
|
||||
import lombok.SneakyThrows;
|
||||
import net.woggioni.jpacrepo.model.Hasher;
|
||||
import net.woggioni.jpacrepo.model.MD5InputStream;
|
||||
import net.woggioni.jpacrepo.model.Parser;
|
||||
import net.woggioni.jpacrepo.pacbase.PkgData;
|
||||
import net.woggioni.jpacrepo.service.PacmanServiceRemote;
|
||||
import net.woggioni.jwo.JWO;
|
||||
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
|
||||
import org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.naming.*;
|
||||
import javax.ws.rs.client.*;
|
||||
@@ -23,30 +24,39 @@ import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ClientTest
|
||||
{
|
||||
@Test
|
||||
public void testGET()
|
||||
{
|
||||
public class ClientTest {
|
||||
|
||||
private static ObjectMapper om;
|
||||
|
||||
static {
|
||||
om = new ObjectMapper();
|
||||
JaxbAnnotationModule module = new JaxbAnnotationModule();
|
||||
om.registerModule(module);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void testGET() {
|
||||
ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance();
|
||||
RegisterBuiltin.register(instance);
|
||||
instance.registerProvider(ResteasyJacksonProvider.class);
|
||||
// instance.registerProvider(ResteasyJacksonProvider.class);
|
||||
Client client = ClientBuilder.newClient();
|
||||
UriBuilder builder = UriBuilder.fromUri("http://odroid-u3:8080/").path("jpacrepo/rest/pkg/search");
|
||||
UriBuilder builder = UriBuilder.fromUri("http://woggioni.net/").path("jpacrepo/rest/pkg/search");
|
||||
// builder.queryParam("name", "linux");
|
||||
// builder.queryParam("version", "324");
|
||||
builder.queryParam("md5sum", "19787793429AF74D4D2D09890247E2EC");
|
||||
WebTarget target = client.target(builder.build());
|
||||
Invocation invocation = target.request().accept("application/xml").buildGet();
|
||||
Response response = invocation.invoke();
|
||||
if (response.getStatusInfo() == Response.Status.OK)
|
||||
{
|
||||
if (response.getStatusInfo() == Response.Status.OK) {
|
||||
PkgData pkg = response.readEntity(PkgData.class);
|
||||
System.out.println(new XStream().toXML(pkg));
|
||||
om.writeValue(System.out, pkg);
|
||||
} else {
|
||||
throw JWO.newThrowable(RuntimeException.class,
|
||||
"Server returned %d",
|
||||
response.getStatusInfo().getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPUT() throws Exception
|
||||
{
|
||||
ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance();
|
||||
@@ -65,7 +75,6 @@ public class ClientTest
|
||||
assert Response.Status.CREATED.getStatusCode() == response.getStatus();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashTest() throws Exception
|
||||
{
|
||||
String[] files = new String[]{"/var/cache/pacman/pkg/mesa-10.4.5-1-x86_64.pkg.tar.xz", "/var/cache/pacman/pkg/mesa-10.5.3-1-x86_64.pkg.tar.xz"};
|
||||
@@ -93,7 +102,7 @@ public class ClientTest
|
||||
h.read(out, 0, (int) a);
|
||||
System.out.println(h.digest());
|
||||
|
||||
PkgData p = Parser.parseFile(new File(file));
|
||||
PkgData p = Parser.parseFile(Paths.get(file));
|
||||
System.out.println(p.md5sum());
|
||||
|
||||
}
|
||||
@@ -117,7 +126,6 @@ public class ClientTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeStatelessBean() throws Exception
|
||||
{
|
||||
Properties prop = new Properties();
|
||||
|
@@ -1,46 +1,50 @@
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
|
||||
import lombok.SneakyThrows;
|
||||
import net.woggioni.jpacrepo.model.Parser;
|
||||
import net.woggioni.jpacrepo.pacbase.CompressionFormat;
|
||||
import net.woggioni.jpacrepo.pacbase.PkgData;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
||||
import org.apache.commons.io.filefilter.RegexFileFilter;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by walter on 22/03/15.
|
||||
*/
|
||||
public class ParseTest
|
||||
{
|
||||
// @Test
|
||||
public void test()
|
||||
{
|
||||
Collection<File> ls = FileUtils.listFiles(new File("/var/cache/pacman/pkg"), new RegexFileFilter(".*\\.pkg\\.tar\\.xz"), DirectoryFileFilter.DIRECTORY);
|
||||
int i = 0;
|
||||
List<PkgData> lista = new ArrayList<>();
|
||||
for (File file : ls)
|
||||
{
|
||||
PkgData data = Parser.parseFile(file);
|
||||
lista.add(data);
|
||||
//System.out.println(new XStream().toXML(data));
|
||||
// if(i++>10) break;
|
||||
}
|
||||
System.out.print(lista);
|
||||
public class ParseTest {
|
||||
|
||||
@SneakyThrows
|
||||
public void test() {
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
JaxbAnnotationModule module = new JaxbAnnotationModule();
|
||||
om.registerModule(module);
|
||||
Pattern pattern = Pattern.compile(".*\\.pkg\\.tar\\.(zst)");
|
||||
Files.list(Paths.get("/var/cache/pacman/pkg"))
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(p -> pattern.matcher(p.getFileName().toString()).matches())
|
||||
.map(path -> Parser.parseFile(path, CompressionFormat.guess(path)))
|
||||
.limit(10)
|
||||
.map(new Function<PkgData, String>() {
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public String apply(PkgData pkgData) {
|
||||
return om.writeValueAsString(pkgData);
|
||||
}
|
||||
})
|
||||
.forEach(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTest()
|
||||
{
|
||||
String[] files = new String[]{"/home/walter/Scaricati/oh-my-zsh-git-3912.d310fac-1-any.pkg.tar.xz"};
|
||||
|
||||
for (String file : files)
|
||||
{
|
||||
PkgData data = Parser.parseFile(new File(file));
|
||||
System.out.println(new XStream().toXML(data));
|
||||
}
|
||||
public void test2() {
|
||||
List<String> l = Arrays.asList("");
|
||||
Type t = ((ParameterizedType)(l.getClass().getGenericSuperclass())).getActualTypeArguments()[0];
|
||||
TypeVariable t2 = l.getClass().getTypeParameters()[0];
|
||||
Type[] bounds = t2.getBounds();
|
||||
System.out.println(bounds[0]);
|
||||
System.out.println(bounds[1]);
|
||||
// GenericEntity<List<String>> entity = new GenericEntity<List<String>>(l, List<String>.getType());
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>net.woggioni.jpacrepo.pacbase.PkgData</class>
|
||||
<class>net.woggioni.jpacrepo.pacbase.PkgName</class>
|
||||
<class>net.woggioni.jpacrepo.pacbase.PkgId</class>
|
||||
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
|
||||
|
49
src/test/scala/net/woggioni/jpacrepo/client/SyncDbTest.scala
Normal file
49
src/test/scala/net/woggioni/jpacrepo/client/SyncDbTest.scala
Normal file
@@ -0,0 +1,49 @@
|
||||
package net.woggioni.jpacrepo.client
|
||||
|
||||
import java.io.InputStream
|
||||
import java.util.Properties
|
||||
|
||||
import javax.naming.{Context, InitialContext, NameClassPair, NamingEnumeration, NamingException}
|
||||
import net.woggioni.jpacrepo.service.PacmanServiceRemote
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
|
||||
class SyncDbTest extends AnyFlatSpec {
|
||||
|
||||
private def traverseJndiNode(nodeName: String, context: Context) {
|
||||
try {
|
||||
val list = context.list(nodeName)
|
||||
while (list.hasMore) {
|
||||
val childName = nodeName + list.next.getName
|
||||
System.out.println(childName)
|
||||
traverseJndiNode(childName, context)
|
||||
}
|
||||
} catch {
|
||||
case _ : NamingException =>
|
||||
}
|
||||
}
|
||||
|
||||
"it" should "be possible to invoke syncDB remotely" in {
|
||||
val prop = new Properties
|
||||
val in = getClass.getClassLoader.getResourceAsStream("jboss-ejb-client.properties")
|
||||
prop.load(in)
|
||||
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming")
|
||||
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory")
|
||||
prop.put(Context.PROVIDER_URL, "http-remoting://localhost:5080")
|
||||
// prop.put(Context.PROVIDER_URL, "http-remoting://nuc:8080");
|
||||
// prop.put(Context.PROVIDER_URL, "remote://odroid-u3:4447");
|
||||
prop.put(Context.SECURITY_PRINCIPAL, "walter")
|
||||
prop.put(Context.SECURITY_CREDENTIALS, "27ff5990757d1d")
|
||||
// prop.put(Context.SECURITY_PRINCIPAL, "admin");
|
||||
// prop.put(Context.SECURITY_CREDENTIALS, "123456");
|
||||
prop.put("jboss.naming.client.ejb.context", true)
|
||||
val context = new InitialContext(prop)
|
||||
val ctx = new InitialContext(prop)
|
||||
traverseJndiNode("/", context)
|
||||
// final PacmanService stateService = (PacmanService) ctx.lookup("/jpacrepo-1.0/remote/PacmanServiceEJB!service.PacmanService");
|
||||
val service = ctx.lookup("/jpacrepo_2.13-2.0/PacmanServiceEJB!net.woggioni.jpacrepo.service.PacmanServiceRemote").asInstanceOf[PacmanServiceRemote]
|
||||
// List<PkgData> pkgs = service.searchPackage("google-earth", null, null, 1, 10);
|
||||
// System.out.println(new XStream().toXML(pkgs));
|
||||
service.syncDB()
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package net.woggioni.jpacrepo.config
|
||||
|
||||
import net.woggioni.jpacrepo.factory.BeanFactory
|
||||
import org.jboss.weld.environment.se.Weld
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.must.Matchers
|
||||
|
||||
class AppConfigTest extends AnyFlatSpec with Matchers {
|
||||
|
||||
private val weld = new Weld
|
||||
weld.disableDiscovery()
|
||||
// weld.alternatives(classOf[TestPersistenceProducer])
|
||||
weld.beanClasses(
|
||||
// classOf[PacmanServiceEJB],
|
||||
// classOf[PacmanWebService],
|
||||
// classOf[AppConfig],
|
||||
classOf[BeanFactory],
|
||||
)
|
||||
val container = weld.initialize()
|
||||
"test" should "pass" in {
|
||||
val appConfig = container.select(classOf[AppConfig]).get()
|
||||
println(appConfig.repoFolder)
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package net.woggioni.jpacrepo.pacbase
|
||||
import java.nio.file.{Files, Path, Paths}
|
||||
import java.util
|
||||
import java.util.regex.Pattern
|
||||
import java.util.stream.Collectors
|
||||
|
||||
import javax.xml.bind.annotation.{XmlAccessType, XmlAccessorType, XmlElement, XmlRootElement}
|
||||
import javax.xml.bind.{JAXBContext, Marshaller}
|
||||
import net.woggioni.jpacrepo.model.Parser
|
||||
import net.woggioni.jpacrepo.service.PkgDataList
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
|
||||
import scala.jdk.CollectionConverters._
|
||||
import scala.annotation.meta.field
|
||||
|
||||
@XmlRootElement(name = "List")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
class JaxbList2[T] private (@(XmlElement @field)(name = "Item") private val list : util.List[T]) {
|
||||
def this(s : Seq[T]) {
|
||||
this(s.toList.asJava)
|
||||
}
|
||||
|
||||
def this() {
|
||||
this(new util.ArrayList[T]())
|
||||
}
|
||||
}
|
||||
|
||||
class MarshalTest extends AnyFlatSpec {
|
||||
|
||||
"asdfs" should "sdfsd" in {
|
||||
val context = JAXBContext.newInstance(classOf[PkgId], classOf[PkgDataList])
|
||||
val mar = context.createMarshaller
|
||||
mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true)
|
||||
val pkgId2 = new PkgId
|
||||
pkgId2.name = "linux"
|
||||
pkgId2.version = "4.6.1"
|
||||
pkgId2.arch = "x86_64"
|
||||
val pattern = Pattern.compile(".*\\.pkg\\.tar\\.(zst)")
|
||||
val pkgDatas = Files.list(Paths.get("/var/cache/pacman/pkg"))
|
||||
.filter(Files.isRegularFile(_))
|
||||
.filter((p: Path) => pattern.matcher(p.getFileName.toString).matches)
|
||||
.limit(10)
|
||||
.map(Parser.parseFile)
|
||||
.collect(Collectors.toList[PkgData])
|
||||
val list = new PkgDataList(pkgDatas)
|
||||
mar.marshal(list, System.out)
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package net.woggioni.jpacrepo.sample
|
||||
|
||||
import net.woggioni.jpacrepo.persistence.InitialSchemaAction
|
||||
import net.woggioni.jpacrepo.version.VersionComparator
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class ExampleSpec extends AnyFlatSpec with Matchers {
|
||||
|
||||
// "A Stack" should "pop values in last-in-first-out order" in {
|
||||
// val stack = new mutable.Stack[Int]
|
||||
// stack.push(1)
|
||||
// stack.push(2)
|
||||
// stack.pop() should be (2)
|
||||
// stack.pop() should be (1)
|
||||
// }
|
||||
//
|
||||
// it should "throw NoSuchElementException if an empty stack is popped" in {
|
||||
// val emptyStack = new mutable.Stack[Int]
|
||||
// a [NoSuchElementException] should be thrownBy {
|
||||
// emptyStack.pop()
|
||||
// }
|
||||
// }
|
||||
|
||||
"sdfgf" should "dfgfd" in {
|
||||
val initial = InitialSchemaAction("none")
|
||||
println(initial)
|
||||
}
|
||||
}
|
@@ -1,11 +1,9 @@
|
||||
package net.woggioni.jpacrepo.service
|
||||
|
||||
import javax.enterprise.util.TypeLiteral
|
||||
import net.woggioni.jpacrepo.context.ApplicationContext
|
||||
import net.woggioni.jpacrepo.factory.BeanFactory
|
||||
import net.woggioni.jpacrepo.persistence.TestPersistenceProducer
|
||||
import org.jboss.weld.environment.se.Weld
|
||||
import org.junit.Test
|
||||
|
||||
//object WeldContainer {
|
||||
// private val weld = new Weld
|
||||
@@ -47,7 +45,6 @@ class PacmanServiceEJBTest {
|
||||
classOf[BeanFactory],
|
||||
)
|
||||
|
||||
@Test
|
||||
def test = {
|
||||
val container = weld.initialize()
|
||||
try {
|
||||
|
@@ -26,4 +26,8 @@ class PacmanWebServiceTest {
|
||||
// val res = response.getEntity
|
||||
// response.getStatus
|
||||
// }
|
||||
|
||||
def boh = {
|
||||
println(System.getProperty("net.woggioni.jpacrepo.configuration.file"))
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package net.woggioni.jpacrepo.version
|
||||
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
class VersionComparatorSpec extends AnyFlatSpec with Matchers {
|
||||
"Version sorting" should "work as expected" in {
|
||||
val vc = new VersionComparator
|
||||
val originalList = List("1.0", "2.0", "3.0", "5.6.7.arch1-1", "5.6.7.arch3-1", "5.6.7.arch3-2", "20200421.78c0348-1")
|
||||
val shuffledList = new Random(101325).shuffle(originalList)
|
||||
val sortedList = shuffledList.sorted(Ordering.comparatorToOrdering(vc))
|
||||
sortedList should be (originalList)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user