This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-indexer.git


The following commit(s) were added to refs/heads/master by this push:
     new f088062  [MINDEXER-161] Make project Java 11 (#207)
f088062 is described below

commit f0880625eed983bf13335d34ac7823b646ae56fe
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Sun Jun 19 23:27:50 2022 +0200

    [MINDEXER-161] Make project Java 11 (#207)
    
    Changes:
    - requires latest Java LTS to build
    - requires latest Maven to build
    - uses `--release` to set Java 11 level
    - drop animal sniffer as JDK does all now
    
    The goal is to keep project stick to latest LTS Java, latest Maven
    and then target the required Java level using new release switch.
---
 .github/workflows/maven-verify.yml                 |   4 +
 Jenkinsfile                                        |   2 +-
 .../index/cli/AbstractNexusIndexerCliTest.java     |   4 +-
 .../maven/index/updater/DefaultIndexUpdater.java   |   8 +-
 .../org/apache/maven/index/NexusIndexerTest.java   |   3 +-
 .../org/apache/maven/index/reader/TestUtils.java   |  21 ++--
 pom.xml                                            | 133 +++++++++++----------
 ...ava => Java11HttpClientSmoSearchTransport.java} |  44 ++++---
 .../backend/smo/internal/SmoSearchBackendImpl.java |   6 +-
 9 files changed, 125 insertions(+), 100 deletions(-)

diff --git a/.github/workflows/maven-verify.yml 
b/.github/workflows/maven-verify.yml
index 857ce59..bb458cc 100644
--- a/.github/workflows/maven-verify.yml
+++ b/.github/workflows/maven-verify.yml
@@ -25,5 +25,9 @@ jobs:
   build:
     name: Verify
     uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v2
+    with:
+      ff-run: false
+      maven_version: 3.8.5
+      jdk-matrix: '[ "17" ]'
 
 
diff --git a/Jenkinsfile b/Jenkinsfile
index b710f7b..99ad149 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -17,4 +17,4 @@
  * under the License.
  */
 
-asfMavenTlpStdBuild( 'jdks' : [ "8", "11", "17" ] )
+asfMavenTlpStdBuild( 'jdks' : [ "17" ] )
diff --git 
a/indexer-cli/src/test/java/org/apache/maven/index/cli/AbstractNexusIndexerCliTest.java
 
b/indexer-cli/src/test/java/org/apache/maven/index/cli/AbstractNexusIndexerCliTest.java
index 63b0e26..e7d6b14 100644
--- 
a/indexer-cli/src/test/java/org/apache/maven/index/cli/AbstractNexusIndexerCliTest.java
+++ 
b/indexer-cli/src/test/java/org/apache/maven/index/cli/AbstractNexusIndexerCliTest.java
@@ -80,7 +80,7 @@ public abstract class AbstractNexusIndexerCliTest
         out = new OutputStream()
         {
 
-            private StringBuffer buf = new StringBuffer();
+            private StringBuilder buf = new StringBuilder();
 
             @Override
             public void write( int b )
@@ -95,7 +95,7 @@ public abstract class AbstractNexusIndexerCliTest
             public String toString()
             {
                 String string = buf.toString();
-                buf = new StringBuffer();
+                buf = new StringBuilder();
                 return string;
             }
         };
diff --git 
a/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
 
b/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
index 88b4c6d..fab4622 100644
--- 
a/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
+++ 
b/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
@@ -35,6 +35,7 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -540,8 +541,6 @@ public class DefaultIndexUpdater
     {
         private static final String CHUNKS_FILENAME = "chunks.lst";
 
-        private static final String CHUNKS_FILE_ENCODING = "UTF-8";
-
         private final IndexUpdateResult result;
 
         private final ArrayList<String> newChunks = new ArrayList<>();
@@ -612,7 +611,7 @@ public class DefaultIndexUpdater
         {
             File chunksFile = new File( dir, CHUNKS_FILENAME );
             try ( BufferedOutputStream os = new BufferedOutputStream( new 
FileOutputStream( chunksFile, true ) ); //
-                            Writer w = new OutputStreamWriter( os, 
CHUNKS_FILE_ENCODING ) )
+                            Writer w = new OutputStreamWriter( os, 
StandardCharsets.UTF_8 ) )
             {
                 for ( String filename : newChunks )
                 {
@@ -630,7 +629,8 @@ public class DefaultIndexUpdater
 
             File chunksFile = new File( dir, CHUNKS_FILENAME );
             try ( BufferedReader r =
-                new BufferedReader( new InputStreamReader( new 
FileInputStream( chunksFile ), CHUNKS_FILE_ENCODING ) ) )
+                new BufferedReader( new InputStreamReader(
+                        new FileInputStream( chunksFile ), 
StandardCharsets.UTF_8 ) ) )
             {
                 String str;
                 while ( ( str = r.readLine() ) != null )
diff --git 
a/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java 
b/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java
index d08f951..b4aa599 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java
@@ -25,6 +25,7 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -334,7 +335,7 @@ public class NexusIndexerTest
         StringWriter ressw = new StringWriter();
         PrintWriter respw = new PrintWriter( ressw );
 
-        BufferedReader reader = new BufferedReader( new FileReader( 
expectedResults ) );
+        BufferedReader reader = new BufferedReader( new FileReader( 
expectedResults, StandardCharsets.UTF_8 ) );
         String currentline;
 
         while ( ( currentline = reader.readLine() ) != null )
diff --git 
a/indexer-reader/src/test/java/org/apache/maven/index/reader/TestUtils.java 
b/indexer-reader/src/test/java/org/apache/maven/index/reader/TestUtils.java
index 2e6912b..54c26b7 100644
--- a/indexer-reader/src/test/java/org/apache/maven/index/reader/TestUtils.java
+++ b/indexer-reader/src/test/java/org/apache/maven/index/reader/TestUtils.java
@@ -25,10 +25,9 @@ import java.util.Map;
 import java.util.TreeSet;
 import java.util.function.Function;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 
-import static com.google.common.collect.Iterables.concat;
-import static java.util.Collections.singletonList;
 import static org.apache.maven.index.reader.Utils.*;
 
 /**
@@ -60,12 +59,18 @@ public final class TestUtils
   {
     final TreeSet<String> allGroupsSet = new TreeSet<>();
     final TreeSet<String> rootGroupsSet = new TreeSet<>();
-    return StreamSupport.stream(
-            concat( singletonList( descriptor( repoId ) ), iterable, 
singletonList( allGroups( allGroupsSet ) ),
-                    // placeholder, will be recreated at the end with proper 
content
-                    singletonList( rootGroups( rootGroupsSet ) )
-                    // placeholder, will be recreated at the end with proper 
content
-            ).spliterator(), false ).map( rec ->
+    return Stream.concat(
+            Stream.of( descriptor( repoId ) ),
+            Stream.concat(
+                    StreamSupport.stream( iterable.spliterator(), false ),
+                    Stream.concat(
+                            Stream.of( allGroups( allGroupsSet ) ),
+                            // placeholder, will be recreated at the end with 
proper content
+                            Stream.of( rootGroups( rootGroupsSet ) )
+                    )
+            )
+            // placeholder, will be recreated at the end with proper content
+    ).map( rec ->
     {
       if ( Type.DESCRIPTOR == rec.getType() )
       {
diff --git a/pom.xml b/pom.xml
index 49c2cf7..8b30662 100644
--- a/pom.xml
+++ b/pom.xml
@@ -84,7 +84,12 @@ under the License.
   </distributionManagement>
 
   <properties>
-    <javaVersion>8</javaVersion>
+    <javaVersion>11</javaVersion>
+    <maven.compiler.source>${javaVersion}</maven.compiler.source>
+    <maven.compiler.target>${javaVersion}</maven.compiler.target>
+    <minimalMavenBuildVersion>3.8.5</minimalMavenBuildVersion>
+    <minimalJavaBuildVersion>17</minimalJavaBuildVersion>
+
     <surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile>
     <failsafe.redirectTestOutputToFile>true</failsafe.redirectTestOutputToFile>
     
<checkstyle.violation.ignore>MagicNumber,ParameterNumber,MethodLength,JavadocType,AvoidNestedBlocks,InterfaceIsType</checkstyle.violation.ignore>
@@ -302,7 +307,71 @@ under the License.
   </modules>
 
   <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.gaul</groupId>
+          <artifactId>modernizer-maven-plugin</artifactId>
+          <version>2.4.0</version>
+          <executions>
+            <execution>
+              <id>modernizer</id>
+              <phase>verify</phase>
+              <goals>
+                <goal>modernizer</goal>
+              </goals>
+            </execution>
+          </executions>
+          <configuration>
+            <javaVersion>${javaVersion}</javaVersion>
+          </configuration>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <configuration>
+            <release>${javaVersion}</release>
+          </configuration>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-checkstyle-plugin</artifactId>
+          <version>3.1.2</version>
+          <dependencies>
+            <dependency>
+              <groupId>com.puppycrawl.tools</groupId>
+              <artifactId>checkstyle</artifactId>
+              <version>10.3</version>
+            </dependency>
+            <dependency>
+              <groupId>org.apache.maven.shared</groupId>
+              <artifactId>maven-shared-resources</artifactId>
+              <version>4</version>
+            </dependency>
+          </dependencies>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-site-plugin</artifactId>
+          <configuration>
+            
<topSiteURL>scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}</topSiteURL>
+          </configuration>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-javadoc-plugin</artifactId>
+          <configuration>
+            <doclint>none</doclint>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
     <plugins>
+      <plugin>
+        <groupId>org.gaul</groupId>
+        <artifactId>modernizer-maven-plugin</artifactId>
+      </plugin>
+
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
@@ -314,26 +383,6 @@ under the License.
         </configuration>
       </plugin>
 
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>animal-sniffer-maven-plugin</artifactId>
-        <configuration>
-          <signature>
-            <groupId>org.codehaus.mojo.signature</groupId>
-            <artifactId>java1${javaVersion}</artifactId>
-            <version>1.0</version>
-          </signature>
-        </configuration>
-        <executions>
-          <execution>
-            <id>check-java-compat</id>
-            <phase>process-classes</phase>
-            <goals>
-              <goal>check</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
       <plugin>
         <groupId>org.apache.rat</groupId>
         <artifactId>apache-rat-plugin</artifactId>
@@ -346,7 +395,7 @@ under the License.
             </goals>
             <configuration>
               <excludes combine.children="append">
-                <exclude>README.md</exclude>
+                <exclude>*.md</exclude>
                 <exclude>.gitignore</exclude>
                 <exclude>NOTICE</exclude>
                 <exclude>**/packageinfo</exclude>
@@ -370,46 +419,6 @@ under the License.
         </executions>
       </plugin>
     </plugins>
-    <pluginManagement>
-      <plugins>
-        <plugin>
-          <groupId>org.codehaus.mojo</groupId>
-          <artifactId>animal-sniffer-maven-plugin</artifactId>
-          <version>1.21</version>
-        </plugin>
-        <plugin>
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-checkstyle-plugin</artifactId>
-          <version>3.1.2</version>
-          <dependencies>
-            <dependency>
-              <groupId>com.puppycrawl.tools</groupId>
-              <artifactId>checkstyle</artifactId>
-              <version>9.3</version>
-            </dependency>
-            <dependency>
-              <groupId>org.apache.maven.shared</groupId>
-              <artifactId>maven-shared-resources</artifactId>
-              <version>4</version>
-            </dependency>
-          </dependencies>
-        </plugin>
-        <plugin>
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-site-plugin</artifactId>
-          <configuration>
-            
<topSiteURL>scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}</topSiteURL>
-          </configuration>
-        </plugin>
-        <plugin>
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-javadoc-plugin</artifactId>
-          <configuration>
-            <doclint>none</doclint>
-          </configuration>
-        </plugin>
-      </plugins>
-    </pluginManagement>
   </build>
 
   <reporting>
diff --git 
a/search-backend-smo/src/main/java/org/apache/maven/search/backend/smo/internal/UrlConnectionSmoSearchTransport.java
 
b/search-backend-smo/src/main/java/org/apache/maven/search/backend/smo/internal/Java11HttpClientSmoSearchTransport.java
similarity index 51%
rename from 
search-backend-smo/src/main/java/org/apache/maven/search/backend/smo/internal/UrlConnectionSmoSearchTransport.java
rename to 
search-backend-smo/src/main/java/org/apache/maven/search/backend/smo/internal/Java11HttpClientSmoSearchTransport.java
index a40a78f..58bd0ab 100644
--- 
a/search-backend-smo/src/main/java/org/apache/maven/search/backend/smo/internal/UrlConnectionSmoSearchTransport.java
+++ 
b/search-backend-smo/src/main/java/org/apache/maven/search/backend/smo/internal/Java11HttpClientSmoSearchTransport.java
@@ -20,40 +20,46 @@ package org.apache.maven.search.backend.smo.internal;
  */
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.HttpURLConnection;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.util.Scanner;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
 
 import org.apache.maven.search.SearchRequest;
 
 /**
- * {@link java.net.HttpURLConnection} backed transport.
+ * Java 11 {@link HttpClient} backed transport.
  */
-public class UrlConnectionSmoSearchTransport extends SmoSearchTransportSupport
+public class Java11HttpClientSmoSearchTransport extends 
SmoSearchTransportSupport
 {
+    private final HttpClient client = HttpClient.newBuilder().followRedirects( 
HttpClient.Redirect.NEVER ).build();
+
     @Override
     public String fetch( SearchRequest searchRequest, String serviceUri ) 
throws IOException
     {
-        HttpURLConnection httpConnection = (HttpURLConnection) new URL( 
serviceUri ).openConnection();
-        httpConnection.setInstanceFollowRedirects( false );
-        httpConnection.setRequestProperty( "User-Agent", getUserAgent() );
-        httpConnection.setRequestProperty( "Accept", "application/json" );
-        int httpCode = httpConnection.getResponseCode();
-        if ( httpCode == HttpURLConnection.HTTP_OK )
+        HttpRequest request = HttpRequest.newBuilder()
+                .uri( URI.create( serviceUri ) )
+                .header( "User-Agent", getUserAgent() )
+                .header( "Accept", "application/json" )
+                .GET()
+                .build();
+        try
         {
-            try ( InputStream inputStream = httpConnection.getInputStream() )
+            HttpResponse<String> response = client.send( request, 
HttpResponse.BodyHandlers.ofString() );
+            if ( response.statusCode() == HttpURLConnection.HTTP_OK )
+            {
+                return response.body();
+            }
+            else
             {
-                try ( Scanner scanner = new Scanner( inputStream, 
StandardCharsets.UTF_8.name() ) )
-                {
-                    return scanner.useDelimiter( "\\A" ).next();
-                }
+                throw new IOException( "Unexpected response: " + response );
             }
         }
-        else
+        catch ( InterruptedException e )
         {
-            throw new IOException( "Unexpected response code: " + httpCode );
+            Thread.currentThread().interrupt();
+            throw new IOException( e );
         }
     }
 }
diff --git 
a/search-backend-smo/src/main/java/org/apache/maven/search/backend/smo/internal/SmoSearchBackendImpl.java
 
b/search-backend-smo/src/main/java/org/apache/maven/search/backend/smo/internal/SmoSearchBackendImpl.java
index f3df5e8..4405c11 100644
--- 
a/search-backend-smo/src/main/java/org/apache/maven/search/backend/smo/internal/SmoSearchBackendImpl.java
+++ 
b/search-backend-smo/src/main/java/org/apache/maven/search/backend/smo/internal/SmoSearchBackendImpl.java
@@ -82,7 +82,7 @@ public class SmoSearchBackendImpl extends 
SearchBackendSupport implements SmoSea
      */
     public SmoSearchBackendImpl()
     {
-        this( DEFAULT_BACKEND_ID, DEFAULT_REPOSITORY_ID, DEFAULT_SMO_URI, new 
UrlConnectionSmoSearchTransport() );
+        this( DEFAULT_BACKEND_ID, DEFAULT_REPOSITORY_ID, DEFAULT_SMO_URI, new 
Java11HttpClientSmoSearchTransport() );
     }
 
     /**
@@ -153,9 +153,9 @@ public class SmoSearchBackendImpl extends 
SearchBackendSupport implements SmoSea
         return encodeQueryParameterValue( query.getValue() );
     }
 
-    private String encodeQueryParameterValue( String parameterValue ) throws 
UnsupportedEncodingException
+    private String encodeQueryParameterValue( String parameterValue )
     {
-        return URLEncoder.encode( parameterValue, 
StandardCharsets.UTF_8.name() )
+        return URLEncoder.encode( parameterValue, StandardCharsets.UTF_8 )
                 .replace( "+", "%20" );
     }
 

Reply via email to