From 8241df995a0be14eca84cb71e80b8c87ce9344e1 Mon Sep 17 00:00:00 2001 From: Walter Oggioni Date: Wed, 8 May 2019 07:55:59 +0100 Subject: [PATCH] migrated to sbt-misc-plugin --- .gitmodules | 2 +- build.sbt | 117 ++++++------------ nim/lib/htmlutils | 2 +- nim/nim.cfg | 2 +- project/plugins.sbt | 4 +- .../jpacrepo/annotation/CORSManaged.java | 11 -- .../jpacrepo/context/ApplicationContext.java | 14 +-- .../jpacrepo/service/ApplicationConfig.java | 1 - .../oggio88/jpacrepo/service/CORSFilter.java | 38 ------ .../jpacrepo/service/PacmanServiceView.java | 6 +- .../jpacrepo/service/PacmanWebService.java | 2 - .../oggio88/jpacrepo/servlet/FileServlet.java | 12 +- .../com/oggio88/jpacrepo/util/Utility.java | 35 ------ src/main/resources-template/persistence.xml | 21 ++++ src/main/resources/META-INF/persistence.xml | 17 --- .../resources/META-INF/sql/CreateSchema.sql | 1 + 16 files changed, 80 insertions(+), 205 deletions(-) delete mode 100644 src/main/java/com/oggio88/jpacrepo/annotation/CORSManaged.java delete mode 100644 src/main/java/com/oggio88/jpacrepo/service/CORSFilter.java delete mode 100644 src/main/java/com/oggio88/jpacrepo/util/Utility.java create mode 100644 src/main/resources-template/persistence.xml delete mode 100644 src/main/resources/META-INF/persistence.xml create mode 100644 src/main/resources/META-INF/sql/CreateSchema.sql diff --git a/.gitmodules b/.gitmodules index 3646ea6..1c0127e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "nim/htmlutils"] path = nim/lib/htmlutils - url = ssh://oggio88.soon.it:1122/mnt/git/htmlutils + url = ssh://git@woggioni.net:1122/mnt/git/htmlutils diff --git a/build.sbt b/build.sbt index 42f05f6..368cc9b 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,5 @@ -import java.nio.file.{Files, StandardCopyOption} - -import xsbti.compile.CompileAnalysis +import org.oggio88.sbt.{NimPlugin, WildflyPlugin} +import org.oggio88.sbt.ConfigurationFile._ name := "jpacrepo" @@ -9,93 +8,55 @@ organization := "com.oggio88" version := "2.0" resolvers += Resolver.mavenLocal -scalaVersion := "2.12.2" libraryDependencies += "org.tukaani" % "xz" % "1.6" libraryDependencies += "org.apache.commons" % "commons-compress" % "1.14" -libraryDependencies += "javax" % "javaee-api" % "7.0" % "provided" -//libraryDependencies += "javax" % "javaee-api" % "7.0 " +libraryDependencies += "javax" % "javaee-api" % "7.0" % Provided +libraryDependencies += "org.hibernate" % "hibernate-jpamodelgen" % "5.3.6.Final" % Provided -libraryDependencies += "junit" % "junit" % "4.12" % "test" -libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test" -libraryDependencies += "com.thoughtworks.xstream" % "xstream" % "1.4.10" % "test" -libraryDependencies += "commons-io" % "commons-io" % "2.5" % "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 += "junit" % "junit" % "4.12" % Test +libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test +libraryDependencies += "com.thoughtworks.xstream" % "xstream" % "1.4.10" % Test +libraryDependencies += "commons-io" % "commons-io" % "2.5" % Test +libraryDependencies += "org.jboss" % "jboss-ejb-client" % "4.0.0.CR5" % Test -libraryDependencies += "org.hibernate" % "hibernate-jpamodelgen" % "5.2.10.Final" % "provided" - -//libraryDependencies += "org.jboss.resteasy" % "resteasy-jaxrs" % "3.1.3.Final" % "test" -//libraryDependencies += "org.jboss.resteasy" % "resteasy-client" % "3.1.3.Final" -//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" +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-jackson-provider" % "3.0.11.Final" % Test +libraryDependencies += "org.jboss.resteasy" % "resteasy-jaxb-provider" % "3.0.11.Final" % Test enablePlugins(WarPlugin) +enablePlugins(WildflyPlugin) +enablePlugins(NimPlugin) -artifactName := - { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) => - artifact.name + "-" + module.revision + "." + artifact.extension - } +nimCompilerParameters in CompileNim := Seq("-d:release", "-d:serverURL=") +sources in CompileNim := Seq(baseDirectory.value / "nim" / "src" / "jpacrepo.nim") -//javacOptions += "-g" +webappWebInfClasses := true -val compileNim = TaskKey[File]("compileNim", "Compile nim code of web interface", KeyRanks.ATask) -compileNim := +webappPostProcess := { + val baseDir = baseDirectory.value / "nim" / "static" + val nimOutput = (compileNim in CompileNim).value + println(nimOutput) + webappDir: File => { - 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 + IO.copyFile(baseDir / "index.html", webappDir / "index.html") + IO.copyFile(baseDir / "jpacrepo.css", webappDir / "jpacrepo.css") + nimOutput.foreach(file => IO.copyFile(file, webappDir / file.getName)) } +} +lazy val dataSourceJNDI = SettingKey[String]("datasource-jndi", "JNDI name of the application datasource") +lazy val dataBaseAction = SettingKey[String]("database-action", + "value of the property \"javax.persistence.schema-generation.database.action\" in the persistence unit") -webappPostProcess := - { - val baseDir = baseDirectory.value / "nim" / "static" - val nimOutput = compileNim.value - webappDir: File => - { - IO.copyFile(baseDir / "index.html", webappDir / "index.html") - IO.copyFile(baseDir / "jpacrepo.css", webappDir / "jpacrepo.css") - IO.copyFile(nimOutput, webappDir / "jpacrepo.js") - } - } +dataSourceJNDI := "java:/PostgresDS" +dataBaseAction := "none" -val wildflyUsername = SettingKey[String]("wildfly-username", "The account username to use to connect to wildfly with jboss-cli.sh") -val wildflyPassword = SettingKey[String]("wildfly-password", "The account password to use to connect to wildfly with jboss-cli.sh") -val wildflyURL = SettingKey[String]("wildfly-url", "The username to use to connect to wildfly with jboss-cli.sh") - -wildflyUsername := "admin" -wildflyPassword := "123456" -wildflyURL := "localhost:1234" - -val deploy2Wildfly = TaskKey[Unit]("deploy2Wildfly", "Deploy to a wildfly server instance", KeyRanks.ATask) - -deploy2Wildfly := - { - val cmd = s"/opt/wildfly/bin/jboss-cli.sh " + - s"--controller='${wildflyURL.value}' " + - s"--connect --user='${wildflyUsername.value}' " + - 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") - } - } +resourceGenerators in Compile += Def.task({ + Seq(IO.configureFile( + (sourceDirectory in Compile).value / "resources-template" / "persistence.xml", + (resourceManaged in Compile).value / "META-INF" / "persistence.xml", + Map("dataSourceJNDI" -> dataSourceJNDI.value, + "dataBaseAction" -> dataBaseAction.value))) +}).taskValue \ No newline at end of file diff --git a/nim/lib/htmlutils b/nim/lib/htmlutils index c57338f..219509c 160000 --- a/nim/lib/htmlutils +++ b/nim/lib/htmlutils @@ -1 +1 @@ -Subproject commit c57338fc27d773cac2511e1a182b3f11834770ab +Subproject commit 219509c9102330ab0e989e19dc501043c3f8338c diff --git a/nim/nim.cfg b/nim/nim.cfg index 17b9954..6684368 100644 --- a/nim/nim.cfg +++ b/nim/nim.cfg @@ -1 +1 @@ -path="lib" +path="lib/htmlutils/src" diff --git a/project/plugins.sbt b/project/plugins.sbt index ca3d16c..5f91b7c 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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") diff --git a/src/main/java/com/oggio88/jpacrepo/annotation/CORSManaged.java b/src/main/java/com/oggio88/jpacrepo/annotation/CORSManaged.java deleted file mode 100644 index 1802f05..0000000 --- a/src/main/java/com/oggio88/jpacrepo/annotation/CORSManaged.java +++ /dev/null @@ -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 -{ -} \ No newline at end of file diff --git a/src/main/java/com/oggio88/jpacrepo/context/ApplicationContext.java b/src/main/java/com/oggio88/jpacrepo/context/ApplicationContext.java index f7bc1ce..750bc15 100644 --- a/src/main/java/com/oggio88/jpacrepo/context/ApplicationContext.java +++ b/src/main/java/com/oggio88/jpacrepo/context/ApplicationContext.java @@ -8,6 +8,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Optional; import java.util.Properties; /** @@ -30,8 +31,6 @@ public class ApplicationContext public boolean invalidateCache = true; - public boolean cors_enabled; - public ApplicationContext(String propertyFile) { systemProperties = new Properties(); @@ -40,11 +39,10 @@ public class ApplicationContext try { input = new FileInputStream(propertyFile); - // load a properties file systemProperties.load(input); - // get the property value and print it out - systemProperties.getProperty("RepoFolder"); - repoFolder = systemProperties.getProperty("RepoFolder"); + repoFolder = Optional.ofNullable( + System.getProperty("com.oggio88.jpacrepo.RepoFolder")).orElse( + systemProperties.getProperty("RepoFolder")); } 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() diff --git a/src/main/java/com/oggio88/jpacrepo/service/ApplicationConfig.java b/src/main/java/com/oggio88/jpacrepo/service/ApplicationConfig.java index abc7646..a5c9998 100644 --- a/src/main/java/com/oggio88/jpacrepo/service/ApplicationConfig.java +++ b/src/main/java/com/oggio88/jpacrepo/service/ApplicationConfig.java @@ -24,7 +24,6 @@ public class ApplicationConfig extends Application { HashSet> c = new HashSet<>(); c.add(PacmanWebService.class); - c.add(CORSFilter.class); classes = Collections.unmodifiableSet(c); } diff --git a/src/main/java/com/oggio88/jpacrepo/service/CORSFilter.java b/src/main/java/com/oggio88/jpacrepo/service/CORSFilter.java deleted file mode 100644 index d92a7fc..0000000 --- a/src/main/java/com/oggio88/jpacrepo/service/CORSFilter.java +++ /dev/null @@ -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 headers = containerResponseContext.getHeaders(); - headers.add("Access-Control-Allow-Origin", "*"); - headers.add("Access-Control-Allow-Headers", "Accept, Accept-Language, Content-Language, Content-Type"); - } - } -} - diff --git a/src/main/java/com/oggio88/jpacrepo/service/PacmanServiceView.java b/src/main/java/com/oggio88/jpacrepo/service/PacmanServiceView.java index 59fab0c..8cc4dea 100644 --- a/src/main/java/com/oggio88/jpacrepo/service/PacmanServiceView.java +++ b/src/main/java/com/oggio88/jpacrepo/service/PacmanServiceView.java @@ -13,10 +13,10 @@ import java.util.Map; @Local public interface PacmanServiceView extends PacmanServiceRemote { - public long countResults(String name, String version, String arch); + long countResults(String name, String version, String arch); - public List searchPackage(String name, String version, String arch, int page, int pageSize); + List searchPackage(String name, String version, String arch, int page, int pageSize); - public List listProperty(String property, Map equalityConditions, Class cls); + List listProperty(String property, Map equalityConditions, Class cls); } diff --git a/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java b/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java index 68a04b0..518a231 100644 --- a/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java +++ b/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java @@ -1,6 +1,5 @@ package com.oggio88.jpacrepo.service; -import com.oggio88.jpacrepo.annotation.CORSManaged; import com.oggio88.jpacrepo.context.ApplicationContext; import com.oggio88.jpacrepo.context.DefaultConfiguration; import com.oggio88.jpacrepo.model.PkgData; @@ -43,7 +42,6 @@ class PkgTuple public long size; } -@CORSManaged @Singleton @Path("/pkg") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) diff --git a/src/main/java/com/oggio88/jpacrepo/servlet/FileServlet.java b/src/main/java/com/oggio88/jpacrepo/servlet/FileServlet.java index 18adff2..e0351ef 100644 --- a/src/main/java/com/oggio88/jpacrepo/servlet/FileServlet.java +++ b/src/main/java/com/oggio88/jpacrepo/servlet/FileServlet.java @@ -17,14 +17,16 @@ import java.io.File; @WebServlet("/archive/*") public class FileServlet extends AbstractFileServlet { + private String root; + @Inject - @DefaultConfiguration - private ApplicationContext ctx; + public FileServlet(@DefaultConfiguration ApplicationContext ctx){ + root = ctx.getRepoFolder(); + } @Override - protected File getFile(HttpServletRequest request) throws IllegalArgumentException - { - return new File(ctx.getSystemProperties().getProperty("RepoFolder"), request.getPathInfo().substring(1)); + protected File getFile(HttpServletRequest request) throws IllegalArgumentException { + return new File(root, request.getPathInfo().substring(1)); } } \ No newline at end of file diff --git a/src/main/java/com/oggio88/jpacrepo/util/Utility.java b/src/main/java/com/oggio88/jpacrepo/util/Utility.java deleted file mode 100644 index b8604f2..0000000 --- a/src/main/java/com/oggio88/jpacrepo/util/Utility.java +++ /dev/null @@ -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); - } - } -} diff --git a/src/main/resources-template/persistence.xml b/src/main/resources-template/persistence.xml new file mode 100644 index 0000000..671b29e --- /dev/null +++ b/src/main/resources-template/persistence.xml @@ -0,0 +1,21 @@ + + + + + ${dataSourceJNDI} + + + + + + + + + + + diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml deleted file mode 100644 index fd457c6..0000000 --- a/src/main/resources/META-INF/persistence.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - java:/PostgresDS - - - - - - - - - diff --git a/src/main/resources/META-INF/sql/CreateSchema.sql b/src/main/resources/META-INF/sql/CreateSchema.sql new file mode 100644 index 0000000..6134692 --- /dev/null +++ b/src/main/resources/META-INF/sql/CreateSchema.sql @@ -0,0 +1 @@ +CREATE SCHEMA IF NOT EXISTS jpacrepo; \ No newline at end of file