You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2022/02/08 15:30:58 UTC

[maven-build-cache-extension] branch master updated: [MBUILDCACHE-15] maven.build.cache.enabled parameter is broken - fix (#6)

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

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-build-cache-extension.git


The following commit(s) were added to refs/heads/master by this push:
     new ff84c65  [MBUILDCACHE-15] maven.build.cache.enabled parameter is broken - fix (#6)
ff84c65 is described below

commit ff84c654e2503bebbd0561928c2840fb03f53f68
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Feb 8 16:29:38 2022 +0100

    [MBUILDCACHE-15] maven.build.cache.enabled parameter is broken - fix (#6)
    
    Co-authored-by: maximilian-novikov-db <ma...@gmail.com>
---
 .../buildcache/RemoteCacheRepositoryNoOp.java      | 83 ++++++++++++++++++++++
 .../buildcache/RemoteCacheRepositoryProvider.java  |  9 ++-
 .../maven/buildcache/xml/CacheConfigImpl.java      | 13 +++-
 3 files changed, 100 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryNoOp.java b/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryNoOp.java
new file mode 100644
index 0000000..a1bc8cc
--- /dev/null
+++ b/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryNoOp.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.buildcache;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Optional;
+import javax.annotation.Nonnull;
+import javax.inject.Named;
+import org.apache.maven.SessionScoped;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.buildcache.xml.Build;
+import org.apache.maven.buildcache.xml.report.CacheReport;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.project.MavenProject;
+
+@SessionScoped
+@Named( "noop" )
+public class RemoteCacheRepositoryNoOp implements RemoteCacheRepository
+{
+
+    @Nonnull
+    @Override
+    public Optional<Build> findBuild( CacheContext context ) throws IOException
+    {
+        return Optional.empty();
+    }
+
+    @Override
+    public void saveBuildInfo( CacheResult cacheResult, Build build ) throws IOException
+    {
+
+    }
+
+    @Override
+    public void saveArtifactFile( CacheResult cacheResult, Artifact artifact ) throws IOException
+    {
+
+    }
+
+    @Override
+    public void saveCacheReport( String buildId, MavenSession session, CacheReport cacheReport ) throws IOException
+    {
+
+    }
+
+    @Override
+    public boolean getArtifactContent( CacheContext context, org.apache.maven.buildcache.xml.build.Artifact artifact,
+            Path target ) throws IOException
+    {
+        return false;
+    }
+
+    @Nonnull
+    @Override
+    public String getResourceUrl( CacheContext context, String filename )
+    {
+        return null;
+    }
+
+    @Nonnull
+    @Override
+    public Optional<Build> findBaselineBuild( MavenProject project )
+    {
+        return Optional.empty();
+    }
+}
diff --git a/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryProvider.java b/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryProvider.java
index 7137d10..9682ae8 100644
--- a/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryProvider.java
+++ b/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryProvider.java
@@ -24,6 +24,7 @@ import javax.inject.Named;
 import javax.inject.Provider;
 import javax.inject.Singleton;
 import org.apache.maven.buildcache.xml.CacheConfig;
+import org.apache.maven.buildcache.xml.CacheState;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 
@@ -42,8 +43,12 @@ public class RemoteCacheRepositoryProvider implements Provider<RemoteCacheReposi
     public RemoteCacheRepositoryProvider( CacheConfig config, PlexusContainer container )
             throws ComponentLookupException
     {
-        config.initialize();
-        String hint = config.getTransport();
+        String hint = "noop";
+        if ( config.initialize() == CacheState.INITIALIZED )
+        {
+            hint = config.getTransport();
+        }
+
         repository = container.lookup( RemoteCacheRepository.class, hint );
     }
 
diff --git a/src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java b/src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java
index bab8e15..fcc5dd8 100644
--- a/src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java
+++ b/src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java
@@ -588,9 +588,16 @@ public class CacheConfigImpl implements org.apache.maven.buildcache.xml.CacheCon
     @Override
     public boolean adjustMetaInfVersion()
     {
-        return Optional.ofNullable( getConfiguration().getProjectVersioning() )
-                .map( ProjectVersioning::isAdjustMetaInf )
-                .orElse( false );
+        if ( isEnabled() )
+        {
+            return Optional.ofNullable( getConfiguration().getProjectVersioning() )
+                    .map( ProjectVersioning::isAdjustMetaInf )
+                    .orElse( false );
+        }
+        else
+        {
+            return false;
+        }
     }
 
     @Nonnull