migrated to sbt-misc-plugin

This commit is contained in:
2019-05-08 07:55:59 +01:00
parent 32197e1c7b
commit 8241df995a
16 changed files with 80 additions and 205 deletions

2
.gitmodules vendored
View File

@@ -1,3 +1,3 @@
[submodule "nim/htmlutils"] [submodule "nim/htmlutils"]
path = nim/lib/htmlutils path = nim/lib/htmlutils
url = ssh://oggio88.soon.it:1122/mnt/git/htmlutils url = ssh://git@woggioni.net:1122/mnt/git/htmlutils

107
build.sbt
View File

@@ -1,6 +1,5 @@
import java.nio.file.{Files, StandardCopyOption} import org.oggio88.sbt.{NimPlugin, WildflyPlugin}
import org.oggio88.sbt.ConfigurationFile._
import xsbti.compile.CompileAnalysis
name := "jpacrepo" name := "jpacrepo"
@@ -9,93 +8,55 @@ organization := "com.oggio88"
version := "2.0" version := "2.0"
resolvers += Resolver.mavenLocal resolvers += Resolver.mavenLocal
scalaVersion := "2.12.2"
libraryDependencies += "org.tukaani" % "xz" % "1.6" libraryDependencies += "org.tukaani" % "xz" % "1.6"
libraryDependencies += "org.apache.commons" % "commons-compress" % "1.14" libraryDependencies += "org.apache.commons" % "commons-compress" % "1.14"
libraryDependencies += "javax" % "javaee-api" % "7.0" % "provided" libraryDependencies += "javax" % "javaee-api" % "7.0" % Provided
//libraryDependencies += "javax" % "javaee-api" % "7.0 " libraryDependencies += "org.hibernate" % "hibernate-jpamodelgen" % "5.3.6.Final" % Provided
libraryDependencies += "junit" % "junit" % "4.12" % "test" libraryDependencies += "junit" % "junit" % "4.12" % Test
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test" libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test
libraryDependencies += "com.thoughtworks.xstream" % "xstream" % "1.4.10" % "test" libraryDependencies += "com.thoughtworks.xstream" % "xstream" % "1.4.10" % Test
libraryDependencies += "commons-io" % "commons-io" % "2.5" % "test" libraryDependencies += "commons-io" % "commons-io" % "2.5" % Test
libraryDependencies += "org.jboss" % "jboss-ejb-client" % "4.0.0.CR5" % "test" libraryDependencies += "org.jboss" % "jboss-ejb-client" % "4.0.0.CR5" % Test
//libraryDependencies += "org.hibernate.javax.persistence" % "hibernate-jpa-2.0-api" % "1.0.1.Final"
libraryDependencies += "org.hibernate" % "hibernate-jpamodelgen" % "5.2.10.Final" % "provided" libraryDependencies += "org.jboss.resteasy" % "resteasy-jaxrs" % "3.0.11.Final" % Test
libraryDependencies += "org.jboss.resteasy" % "resteasy-client" % "3.0.11.Final" % Test
//libraryDependencies += "org.jboss.resteasy" % "resteasy-jaxrs" % "3.1.3.Final" % "test" libraryDependencies += "org.jboss.resteasy" % "resteasy-jackson-provider" % "3.0.11.Final" % Test
//libraryDependencies += "org.jboss.resteasy" % "resteasy-client" % "3.1.3.Final" libraryDependencies += "org.jboss.resteasy" % "resteasy-jaxb-provider" % "3.0.11.Final" % Test
//libraryDependencies += "org.jboss.resteasy" % "resteasy-jackson-provider" % "3.1.3.Final" % "test"
//libraryDependencies += "com.fasterxml.jackson.core" % "jackson-core" % "2.9.0.pr4"
//libraryDependencies += "org.jboss.resteasy" % "resteasy-jaxb-provider" % "3.1.3.Final" % "test"
//libraryDependencies += "org.jboss.spec.javax.servlet" % "jboss-servlet-api_3.1_spec" % "1.0.0.Final" % "provided"
//libraryDependencies += "org.jboss.spec.javax.ws.rs" % "jboss-jaxrs-api_2.0_spec" % "1.0.0.Final"
libraryDependencies += "org.jboss.resteasy" % "resteasy-jaxrs" % "3.0.11.Final"
libraryDependencies += "org.jboss.resteasy" % "resteasy-client" % "3.0.11.Final"
libraryDependencies += "org.jboss.resteasy" % "resteasy-jackson-provider" % "3.0.11.Final"
libraryDependencies += "org.jboss.resteasy" % "resteasy-jaxb-provider" % "3.0.11.Final"
enablePlugins(WarPlugin) enablePlugins(WarPlugin)
enablePlugins(WildflyPlugin)
enablePlugins(NimPlugin)
artifactName := nimCompilerParameters in CompileNim := Seq("-d:release", "-d:serverURL=")
{ (sv: ScalaVersion, module: ModuleID, artifact: Artifact) => sources in CompileNim := Seq(baseDirectory.value / "nim" / "src" / "jpacrepo.nim")
artifact.name + "-" + module.revision + "." + artifact.extension
}
//javacOptions += "-g" webappWebInfClasses := true
val compileNim = TaskKey[File]("compileNim", "Compile nim code of web interface", KeyRanks.ATask) webappPostProcess := {
compileNim :=
{
val result = new File("nim/nimcache/jpacrepo.js")
val cmd = s"nim js -d:release -d:serverURL= nim/src/jpacrepo.nim"
println(cmd)
sys.process.stringToProcess(cmd).! match
{
case 0 =>
case _ => throw new RuntimeException("Error occurred during deploy")
}
result
}
webappPostProcess :=
{
val baseDir = baseDirectory.value / "nim" / "static" val baseDir = baseDirectory.value / "nim" / "static"
val nimOutput = compileNim.value val nimOutput = (compileNim in CompileNim).value
println(nimOutput)
webappDir: File => webappDir: File =>
{ {
IO.copyFile(baseDir / "index.html", webappDir / "index.html") IO.copyFile(baseDir / "index.html", webappDir / "index.html")
IO.copyFile(baseDir / "jpacrepo.css", webappDir / "jpacrepo.css") IO.copyFile(baseDir / "jpacrepo.css", webappDir / "jpacrepo.css")
IO.copyFile(nimOutput, webappDir / "jpacrepo.js") nimOutput.foreach(file => IO.copyFile(file, webappDir / file.getName))
} }
} }
val wildflyUsername = SettingKey[String]("wildfly-username", "The account username to use to connect to wildfly with jboss-cli.sh") lazy val dataSourceJNDI = SettingKey[String]("datasource-jndi", "JNDI name of the application datasource")
val wildflyPassword = SettingKey[String]("wildfly-password", "The account password to use to connect to wildfly with jboss-cli.sh") lazy val dataBaseAction = SettingKey[String]("database-action",
val wildflyURL = SettingKey[String]("wildfly-url", "The username to use to connect to wildfly with jboss-cli.sh") "value of the property \"javax.persistence.schema-generation.database.action\" in the persistence unit")
wildflyUsername := "admin" dataSourceJNDI := "java:/PostgresDS"
wildflyPassword := "123456" dataBaseAction := "none"
wildflyURL := "localhost:1234"
val deploy2Wildfly = TaskKey[Unit]("deploy2Wildfly", "Deploy to a wildfly server instance", KeyRanks.ATask) resourceGenerators in Compile += Def.task({
Seq(IO.configureFile(
deploy2Wildfly := (sourceDirectory in Compile).value / "resources-template" / "persistence.xml",
{ (resourceManaged in Compile).value / "META-INF" / "persistence.xml",
val cmd = s"/opt/wildfly/bin/jboss-cli.sh " + Map("dataSourceJNDI" -> dataSourceJNDI.value,
s"--controller='${wildflyURL.value}' " + "dataBaseAction" -> dataBaseAction.value)))
s"--connect --user='${wildflyUsername.value}' " + }).taskValue
s"--password='${wildflyPassword.value}' " +
s"--command=\'deploy ${(packagedArtifact in(Compile, Keys.`package`)).value._2} --force\'"
println(cmd)
sys.process.stringToProcess(cmd).! match
{
case 0 =>
case _ => throw new RuntimeException("Error occurred during deploy")
}
}

View File

@@ -1 +1 @@
path="lib" path="lib/htmlutils/src"

View File

@@ -1,2 +1,2 @@
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.0.0") addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.0.1")
addSbtPlugin("org.oggio88" % "xsbt-misc-plugin" % "0.1")

View File

@@ -1,11 +0,0 @@
package com.oggio88.jpacrepo.annotation;
import javax.ws.rs.NameBinding;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@NameBinding
@Retention(RetentionPolicy.RUNTIME)
public @interface CORSManaged
{
}

View File

@@ -8,6 +8,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Optional;
import java.util.Properties; import java.util.Properties;
/** /**
@@ -30,8 +31,6 @@ public class ApplicationContext
public boolean invalidateCache = true; public boolean invalidateCache = true;
public boolean cors_enabled;
public ApplicationContext(String propertyFile) public ApplicationContext(String propertyFile)
{ {
systemProperties = new Properties(); systemProperties = new Properties();
@@ -40,11 +39,10 @@ public class ApplicationContext
try try
{ {
input = new FileInputStream(propertyFile); input = new FileInputStream(propertyFile);
// load a properties file
systemProperties.load(input); systemProperties.load(input);
// get the property value and print it out repoFolder = Optional.ofNullable(
systemProperties.getProperty("RepoFolder"); System.getProperty("com.oggio88.jpacrepo.RepoFolder")).orElse(
repoFolder = systemProperties.getProperty("RepoFolder"); systemProperties.getProperty("RepoFolder"));
} }
catch (IOException ex) catch (IOException ex)
{ {
@@ -64,10 +62,6 @@ public class ApplicationContext
} }
} }
} }
String prop = System.getProperty("org.oggio88.jpacrepo.cors");
if (prop != null)
cors_enabled = Boolean.parseBoolean(prop);
} }
public Properties getSystemProperties() public Properties getSystemProperties()

View File

@@ -24,7 +24,6 @@ public class ApplicationConfig extends Application
{ {
HashSet<Class<?>> c = new HashSet<>(); HashSet<Class<?>> c = new HashSet<>();
c.add(PacmanWebService.class); c.add(PacmanWebService.class);
c.add(CORSFilter.class);
classes = Collections.unmodifiableSet(c); classes = Collections.unmodifiableSet(c);
} }

View File

@@ -1,38 +0,0 @@
package com.oggio88.jpacrepo.service;
import com.oggio88.jpacrepo.annotation.CORSManaged;
import com.oggio88.jpacrepo.context.ApplicationContext;
import com.oggio88.jpacrepo.context.DefaultConfiguration;
import javax.inject.Inject;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.util.logging.Logger;
@Provider
@CORSManaged
public class CORSFilter implements ContainerResponseFilter
{
private final Logger log = Logger.getLogger(CORSFilter.class.getName());
@Inject
@DefaultConfiguration
ApplicationContext ctx;
@Override
public void filter(ContainerRequestContext containerRequestContext,
ContainerResponseContext containerResponseContext) throws IOException
{
if (!ctx.cors_enabled)
{
MultivaluedMap<String, Object> headers = containerResponseContext.getHeaders();
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Headers", "Accept, Accept-Language, Content-Language, Content-Type");
}
}
}

View File

@@ -13,10 +13,10 @@ import java.util.Map;
@Local @Local
public interface PacmanServiceView extends PacmanServiceRemote public interface PacmanServiceView extends PacmanServiceRemote
{ {
public long countResults(String name, String version, String arch); long countResults(String name, String version, String arch);
public List<PkgData> searchPackage(String name, String version, String arch, int page, int pageSize); List<PkgData> searchPackage(String name, String version, String arch, int page, int pageSize);
public<T> List<T> listProperty(String property, Map<String,String> equalityConditions, Class<T> cls); <T> List<T> listProperty(String property, Map<String,String> equalityConditions, Class<T> cls);
} }

View File

@@ -1,6 +1,5 @@
package com.oggio88.jpacrepo.service; package com.oggio88.jpacrepo.service;
import com.oggio88.jpacrepo.annotation.CORSManaged;
import com.oggio88.jpacrepo.context.ApplicationContext; import com.oggio88.jpacrepo.context.ApplicationContext;
import com.oggio88.jpacrepo.context.DefaultConfiguration; import com.oggio88.jpacrepo.context.DefaultConfiguration;
import com.oggio88.jpacrepo.model.PkgData; import com.oggio88.jpacrepo.model.PkgData;
@@ -43,7 +42,6 @@ class PkgTuple
public long size; public long size;
} }
@CORSManaged
@Singleton @Singleton
@Path("/pkg") @Path("/pkg")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})

View File

@@ -17,14 +17,16 @@ import java.io.File;
@WebServlet("/archive/*") @WebServlet("/archive/*")
public class FileServlet extends AbstractFileServlet public class FileServlet extends AbstractFileServlet
{ {
private String root;
@Inject @Inject
@DefaultConfiguration public FileServlet(@DefaultConfiguration ApplicationContext ctx){
private ApplicationContext ctx; root = ctx.getRepoFolder();
}
@Override @Override
protected File getFile(HttpServletRequest request) throws IllegalArgumentException protected File getFile(HttpServletRequest request) throws IllegalArgumentException {
{ return new File(root, request.getPathInfo().substring(1));
return new File(ctx.getSystemProperties().getProperty("RepoFolder"), request.getPathInfo().substring(1));
} }
} }

View File

@@ -1,35 +0,0 @@
package com.oggio88.jpacrepo.util;
import java.io.IOException;
import java.io.InputStream;
/**
* Created by walter on 06/06/15.
*/
public class Utility
{
public static String getTemplate(String filename)
{
return new String(readResource("/template/" + filename));
}
public static byte[] readResource(String resourcePath)
{
try
{
InputStream is = Utility.class.getClassLoader().getResourceAsStream(resourcePath);
byte[] res = new byte[is.available()];
if(is.read(res,0, res.length)!= res.length)
{
throw new IOException("Uncompleted read");
}
is.close();
return res;
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="jpacrepo_pu" transaction-type="JTA">
<jta-data-source>${dataSourceJNDI}</jta-data-source>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="${dataBaseAction}"/>
<property name="javax.persistence.schema-generation.create-source" value="script-then-metadata"/>
<property name="javax.persistence.schema-generation.create-script-source"
value="META-INF/sql/CreateSchema.sql"/>
<property name="javax.persistence.schema-generation.drop-source" value="metadata-then-script"/>
<property name="javax.persistence.schema-generation.drop-script-source"
value="META-INF/sql/DropSchema.sql"/>
<property name="eclipselink.logging.level" value="INFO"/>
<property name="hibernate.default_schema" value="jpacrepo"/>
</properties>
</persistence-unit>
</persistence>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="jpacrepo_pu" transaction-type="JTA">
<jta-data-source>java:/PostgresDS</jta-data-source>
<properties>
<!--<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>-->
<property name="javax.persistence.schema-generation.database.action" value="none"/>
<!--<property name="javax.persistence.schema-generation.database.action" value="create"/>-->
<property name="eclipselink.logging.level" value="INFO"/>
<property name="hibernate.default_schema" value="jpacrepo"/>
</properties>
</persistence-unit>
</persistence>

View File

@@ -0,0 +1 @@
CREATE SCHEMA IF NOT EXISTS jpacrepo;