This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/openwebbeans-meecrowave.git
The following commit(s) were added to refs/heads/master by this push: new 2508719 minor change to replace deprecated API by up to date ones 2508719 is described below commit 2508719673a8dc75e8992b20e43aeca595d3a2a4 Author: Romain Manni-Bucau <rmannibu...@gmail.com> AuthorDate: Tue Mar 23 20:30:03 2021 +0100 minor change to replace deprecated API by up to date ones --- .../java/org/apache/meecrowave/Meecrowave.java | 92 +++++++++++----------- .../meecrowave/johnzon/JohnzonBufferTest.java | 8 +- .../apache/meecrowave/doc/generator/Downloads.java | 3 +- .../letencrypt/LetsEncryptReloadLifecycle.java | 42 +++++----- .../meecrowave/maven/MeecrowaveBundleMojo.java | 67 ++++++++-------- 5 files changed, 103 insertions(+), 109 deletions(-) diff --git a/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java b/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java index 450cd79..705567f 100644 --- a/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java +++ b/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java @@ -617,8 +617,8 @@ public class Meecrowave implements AutoCloseable { if (tomcat.getRawConnector() == null && !configuration.isSkipHttp()) { final Connector connector = createConnector(); connector.setPort(configuration.getHttpPort()); - if (connector.getAttribute("connectionTimeout") == null) { - connector.setAttribute("connectionTimeout", "3000"); + if (connector.getProperty("connectionTimeout") == null) { + connector.setProperty("connectionTimeout", "3000"); } tomcat.getService().addConnector(connector); @@ -636,7 +636,7 @@ public class Meecrowave implements AutoCloseable { configuration.getProperties().setProperty("connector.sslhostconfig.sslProtocol", configuration.getSslProtocol()); } if (configuration.getProperties().getProperty("connector.sslhostconfig.hostName") != null) { - httpsConnector.setAttribute("defaultSSLHostConfigName", configuration.getProperties().getProperty("connector.sslhostconfig.hostName")); + httpsConnector.setProperty("defaultSSLHostConfigName", configuration.getProperties().getProperty("connector.sslhostconfig.hostName")); } if (configuration.getKeystoreFile() != null) { configuration.getProperties().setProperty("connector.sslhostconfig.certificateKeystoreFile", configuration.getKeystoreFile()); @@ -646,7 +646,7 @@ public class Meecrowave implements AutoCloseable { } configuration.getProperties().setProperty("connector.sslhostconfig.certificateKeystoreType", configuration.getKeystoreType()); if (configuration.getClientAuth() != null) { - httpsConnector.setAttribute("clientAuth", configuration.getClientAuth()); + httpsConnector.setProperty("clientAuth", configuration.getClientAuth()); } if (configuration.getKeyAlias() != null) { @@ -683,7 +683,7 @@ public class Meecrowave implements AutoCloseable { buildSslHostConfig.forEach(httpsConnector::addSslHostConfig); if (configuration.getDefaultSSLHostConfigName() != null) { - httpsConnector.setAttribute("defaultSSLHostConfigName", configuration.getDefaultSSLHostConfigName()); + httpsConnector.setProperty("defaultSSLHostConfigName", configuration.getDefaultSSLHostConfigName()); } tomcat.getService().addConnector(httpsConnector); if (configuration.isSkipHttp()) { @@ -783,8 +783,8 @@ public class Meecrowave implements AutoCloseable { String::equalsIgnoreCase : String::equals; return certificate != null && !(new File(certificate).exists()) && !equals.test( - Paths.get(System.getProperty("user.home")).resolve(".keystore").toAbsolutePath().normalize().toString(), - Paths.get(certificate).toAbsolutePath().normalize().toString()); + Paths.get(System.getProperty("user.home")).resolve(".keystore").toAbsolutePath().normalize().toString(), + Paths.get(certificate).toAbsolutePath().normalize().toString()); } private void copyCertificateToConfDir(String certificate) { @@ -816,6 +816,7 @@ public class Meecrowave implements AutoCloseable { /** * Store away the current system property for restoring it later * during shutdown. + * * @param backupPropertyMap a Map to store away the previous value before setting the newValue * @param propertyKey * @param newValue @@ -880,12 +881,12 @@ public class Meecrowave implements AutoCloseable { /** * Syntax uses: * <code> - * valves.myValve1._className = org.apache.meecrowave.tomcat.LoggingAccessLogPattern - * valves.myValve1._order = 0 - * - * valves.myValve1._className = SSOVa - * valves.myValve1._order = 1 - * valves.myValve1.showReportInfo = false + * valves.myValve1._className = org.apache.meecrowave.tomcat.LoggingAccessLogPattern + * valves.myValve1._order = 0 + * <p> + * valves.myValve1._className = SSOVa + * valves.myValve1._order = 1 + * valves.myValve1.showReportInfo = false * </code> * * @return the list of valve from the properties. @@ -893,22 +894,22 @@ public class Meecrowave implements AutoCloseable { private List<Valve> buildValves() { final List<Valve> valves = new ArrayList<>(); configuration.getProperties().stringPropertyNames().stream() - .filter(key -> key.startsWith("valves.") && key.endsWith("._className")) - .sorted(comparing(key -> Integer.parseInt(configuration.getProperties() - .getProperty(key.replaceFirst("\\._className$", "._order"), "0")))) - .map(key -> key.split("\\.")) - .filter(parts -> parts.length == 3) - .forEach(key -> { - final String prefix = key[0] + '.' + key[1] + '.'; - final ObjectRecipe recipe = newRecipe(configuration.getProperties().getProperty(prefix + key[2])); - configuration.getProperties().stringPropertyNames().stream() - .filter(it -> it.startsWith(prefix) && !it.endsWith("._order") && !it.endsWith("._className")) - .forEach(propKey -> { - final String value = configuration.getProperties().getProperty(propKey); - recipe.setProperty(propKey.substring(prefix.length()), value); - }); - valves.add(Valve.class.cast(recipe.create(Thread.currentThread().getContextClassLoader()))); - }); + .filter(key -> key.startsWith("valves.") && key.endsWith("._className")) + .sorted(comparing(key -> Integer.parseInt(configuration.getProperties() + .getProperty(key.replaceFirst("\\._className$", "._order"), "0")))) + .map(key -> key.split("\\.")) + .filter(parts -> parts.length == 3) + .forEach(key -> { + final String prefix = key[0] + '.' + key[1] + '.'; + final ObjectRecipe recipe = newRecipe(configuration.getProperties().getProperty(prefix + key[2])); + configuration.getProperties().stringPropertyNames().stream() + .filter(it -> it.startsWith(prefix) && !it.endsWith("._order") && !it.endsWith("._className")) + .forEach(propKey -> { + final String value = configuration.getProperties().getProperty(propKey); + recipe.setProperty(propKey.substring(prefix.length()), value); + }); + valves.add(Valve.class.cast(recipe.create(Thread.currentThread().getContextClassLoader()))); + }); return valves; } @@ -927,19 +928,19 @@ public class Meecrowave implements AutoCloseable { } // Allows to add N Multiple SSLHostConfig elements not including the default one. final Collection<Integer> itemNumbers = configuration.getProperties().stringPropertyNames() - .stream() - .filter(key -> (key.startsWith("connector.sslhostconfig.") && key.split("\\.").length == 4)) - .map(key -> Integer.parseInt(key.split("\\.")[2])) - .collect(toSet()); + .stream() + .filter(key -> (key.startsWith("connector.sslhostconfig.") && key.split("\\.").length == 4)) + .map(key -> Integer.parseInt(key.split("\\.")[2])) + .collect(toSet()); itemNumbers.stream().sorted().forEach(itemNumber -> { final ObjectRecipe recipe = newRecipe(SSLHostConfig.class.getName()); final String prefix = "connector.sslhostconfig." + itemNumber + '.'; configuration.getProperties().stringPropertyNames().stream() - .filter(k -> k.startsWith(prefix)) - .forEach(key -> { - final String keyName = key.split("\\.")[3]; - recipe.setProperty(keyName, configuration.getProperties().getProperty(key)); - }); + .filter(k -> k.startsWith(prefix)) + .forEach(key -> { + final String keyName = key.split("\\.")[3]; + recipe.setProperty(keyName, configuration.getProperties().getProperty(key)); + }); if (!recipe.getProperties().isEmpty()) { final SSLHostConfig sslHostConfig = SSLHostConfig.class.cast(recipe.create()); sslHostConfigs.add(sslHostConfig); @@ -1048,7 +1049,7 @@ public class Meecrowave implements AutoCloseable { } connector = recipe.getProperties().isEmpty() ? new Connector() : Connector.class.cast(recipe.create()); for (final Map.Entry<String, String> attr : attributes.entrySet()) { - connector.setAttribute(attr.getKey(), attr.getValue()); + connector.setProperty(attr.getKey(), attr.getValue()); } } else { connector = new Connector(); @@ -1060,11 +1061,6 @@ public class Meecrowave implements AutoCloseable { final Catalina catalina = new Catalina() { // skip few init we don't need *here* @Override - protected void initDirs() { - // no-op - } - - @Override protected void initStreams() { // no-op } @@ -1135,10 +1131,10 @@ public class Meecrowave implements AutoCloseable { lookupPaths.add("target"); lookupPaths.add("build"); final File file = lookupPaths.stream() - .map(File::new) - .filter(File::isDirectory) - .findFirst() - .map(file1 -> new File(file1, "meecrowave-" + System.nanoTime())).orElse(ownedTempDir); + .map(File::new) + .filter(File::isDirectory) + .findFirst() + .map(file1 -> new File(file1, "meecrowave-" + System.nanoTime())).orElse(ownedTempDir); IO.mkdirs(file); return file.getAbsolutePath(); } diff --git a/meecrowave-core/src/test/java/org/apache/meecrowave/johnzon/JohnzonBufferTest.java b/meecrowave-core/src/test/java/org/apache/meecrowave/johnzon/JohnzonBufferTest.java index c84a11f..33434ce 100644 --- a/meecrowave-core/src/test/java/org/apache/meecrowave/johnzon/JohnzonBufferTest.java +++ b/meecrowave-core/src/test/java/org/apache/meecrowave/johnzon/JohnzonBufferTest.java @@ -16,13 +16,13 @@ */ package org.apache.meecrowave.johnzon; +import org.apache.meecrowave.Meecrowave; +import org.junit.Test; + import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.core.MediaType; -import org.apache.meecrowave.Meecrowave; -import org.junit.Test; - import static org.junit.Assert.assertEquals; public class JohnzonBufferTest { @@ -31,7 +31,7 @@ public class JohnzonBufferTest { DebugJohnzonBufferStrategy.resetCounter(); try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder() .randomHttpPort() - .withJsonpBufferStrategy(DebugJohnzonBufferStrategy.class.getName()) + .jsonpBufferStrategy(DebugJohnzonBufferStrategy.class.getName()) .includePackages("org.superbiz.app.TestJsonEndpoint")).bake()) { final Client client = ClientBuilder.newClient(); try { diff --git a/meecrowave-doc/src/main/java/org/apache/meecrowave/doc/generator/Downloads.java b/meecrowave-doc/src/main/java/org/apache/meecrowave/doc/generator/Downloads.java index 3ca906c..0c29839 100755 --- a/meecrowave-doc/src/main/java/org/apache/meecrowave/doc/generator/Downloads.java +++ b/meecrowave-doc/src/main/java/org/apache/meecrowave/doc/generator/Downloads.java @@ -18,7 +18,6 @@ */ package org.apache.meecrowave.doc.generator; -import org.apache.commons.lang3.text.WordUtils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -200,7 +199,7 @@ public class Downloads { } return new Download( - WordUtils.capitalize(artifactId.replace('-', ' ')), + Character.toUpperCase(artifactId.charAt(0)) + artifactId.substring(1).replace('-', ' '), classifier, version, format, diff --git a/meecrowave-letsencrypt/src/main/java/org/apache/meecrowave/letencrypt/LetsEncryptReloadLifecycle.java b/meecrowave-letsencrypt/src/main/java/org/apache/meecrowave/letencrypt/LetsEncryptReloadLifecycle.java index d1db179..466960b 100644 --- a/meecrowave-letsencrypt/src/main/java/org/apache/meecrowave/letencrypt/LetsEncryptReloadLifecycle.java +++ b/meecrowave-letsencrypt/src/main/java/org/apache/meecrowave/letencrypt/LetsEncryptReloadLifecycle.java @@ -18,7 +18,25 @@ */ package org.apache.meecrowave.letencrypt; -import static java.util.Optional.ofNullable; +import org.apache.coyote.http11.AbstractHttp11Protocol; +import org.apache.meecrowave.logging.tomcat.LogFacade; +import org.apache.meecrowave.runner.Cli; +import org.apache.meecrowave.runner.cli.CliOption; +import org.bouncycastle.openssl.PEMKeyPair; +import org.bouncycastle.openssl.PEMParser; +import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; +import org.bouncycastle.openssl.jcajce.JcaPEMWriter; +import org.shredzone.acme4j.Account; +import org.shredzone.acme4j.AccountBuilder; +import org.shredzone.acme4j.Authorization; +import org.shredzone.acme4j.Certificate; +import org.shredzone.acme4j.Order; +import org.shredzone.acme4j.Session; +import org.shredzone.acme4j.Status; +import org.shredzone.acme4j.challenge.Challenge; +import org.shredzone.acme4j.challenge.Http01Challenge; +import org.shredzone.acme4j.exception.AcmeException; +import org.shredzone.acme4j.util.CSRBuilder; import java.io.BufferedWriter; import java.io.File; @@ -40,25 +58,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.apache.coyote.http11.AbstractHttp11Protocol; -import org.apache.meecrowave.logging.tomcat.LogFacade; -import org.apache.meecrowave.runner.Cli; -import org.apache.meecrowave.runner.cli.CliOption; -import org.bouncycastle.openssl.PEMKeyPair; -import org.bouncycastle.openssl.PEMParser; -import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; -import org.bouncycastle.openssl.jcajce.JcaPEMWriter; -import org.shredzone.acme4j.Account; -import org.shredzone.acme4j.AccountBuilder; -import org.shredzone.acme4j.Authorization; -import org.shredzone.acme4j.Certificate; -import org.shredzone.acme4j.Order; -import org.shredzone.acme4j.Session; -import org.shredzone.acme4j.Status; -import org.shredzone.acme4j.challenge.Challenge; -import org.shredzone.acme4j.challenge.Http01Challenge; -import org.shredzone.acme4j.exception.AcmeException; -import org.shredzone.acme4j.util.CSRBuilder; +import static java.util.Optional.ofNullable; // we depend on bouncycastle but user myst add it to be able to use that // todo: check we can get rid of it and use jaxrs client instead of acme lib @@ -205,7 +205,7 @@ public class LetsEncryptReloadLifecycle implements AutoCloseable, Runnable { } if (challenge.getStatus() != Status.VALID) { - throw new AcmeException("Challenge for domain " + authorization.getDomain() + ", is invalid, exiting iteration"); + throw new AcmeException("Challenge for domain " + authorization.getIdentifier() + ", is invalid, exiting iteration"); } return true; } diff --git a/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java b/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java index a1814d0..b844acf 100644 --- a/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java +++ b/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java @@ -18,38 +18,10 @@ */ package org.apache.meecrowave.maven; -import static java.util.Arrays.asList; -import static java.util.Locale.ENGLISH; -import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; -import static org.apache.maven.plugins.annotations.ResolutionScope.RUNTIME_PLUS_SYSTEM; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.StandardCopyOption; -import java.nio.file.StandardOpenOption; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Properties; -import java.util.stream.Stream; -import java.util.zip.GZIPOutputStream; - import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; -import org.apache.commons.lang3.text.StrSubstitutor; import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.AbstractMojo; @@ -66,6 +38,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.apache.maven.project.ProjectDependenciesResolver; import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder; +import org.apache.meecrowave.lang.Substitutor; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.artifact.DefaultArtifact; @@ -78,6 +51,33 @@ import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.ArtifactResult; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.StandardCopyOption; +import java.nio.file.StandardOpenOption; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; +import java.util.stream.Stream; +import java.util.zip.GZIPOutputStream; + +import static java.util.Arrays.asList; +import static java.util.Locale.ENGLISH; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; +import static org.apache.maven.plugins.annotations.ResolutionScope.RUNTIME_PLUS_SYSTEM; + @Mojo(name = "bundle", requiresDependencyResolution = RUNTIME_PLUS_SYSTEM) public class MeecrowaveBundleMojo extends AbstractMojo { private static final String DELETE_TEXT = "Just there to not loose the folder cause it is empty, you can safely delete."; @@ -253,12 +253,11 @@ public class MeecrowaveBundleMojo extends AbstractMojo { Thread.currentThread().getContextClassLoader().getResourceAsStream("bin/meecrowave." + ext)))) { final File target = new File(distroFolder, "bin/meecrowave." + ext); if (!target.exists()) { - write(target, StrSubstitutor.replace(reader.lines().collect(joining("\n")), - new HashMap<String, String>() {{ - put("main", main); - put("logManager", hasLog4j(distroFolder) ? - "org.apache.logging.log4j.jul.LogManager" : "org.apache.juli.ClassLoaderLogManager"); - }})); + write(target, new Substitutor(new HashMap<String, String>() {{ + put("main", main); + put("logManager", hasLog4j(distroFolder) ? + "org.apache.logging.log4j.jul.LogManager" : "org.apache.juli.ClassLoaderLogManager"); + }}).replace(reader.lines().collect(joining("\n")))); } } catch (final IOException e) { throw new MojoExecutionException(e.getMessage(), e);