Skip to content

Commit

Permalink
Ability to specify the build cache location (#16)
Browse files Browse the repository at this point in the history
* add a configuration field for the build cache location
* defaults to `build-cache` instead of `cache`
* add the remote repository id in the build cache path
  • Loading branch information
gnodet committed May 19, 2022
1 parent b2b7a5d commit 4794ac6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,19 +436,28 @@ private Path buildCacheDir( CacheContext context ) throws IOException

private Path artifactCacheDir( MavenSession session, String groupId, String artifactId ) throws IOException
{
final String localRepositoryRoot = session.getLocalRepository().getBasedir();
final Path path = Paths.get( localRepositoryRoot, "..", "cache", CACHE_IMPLEMENTATION_VERSION, groupId,
artifactId ).normalize();
if ( !Files.exists( path ) )
final Path vga = Paths.get( CACHE_IMPLEMENTATION_VERSION, groupId, artifactId );
final Path path = baseDir( session ).resolve( vga );
Files.createDirectories( path );
return path;
}

private Path baseDir( MavenSession session )
{
String loc = cacheConfig.getLocalRepositoryLocation();
if ( loc != null )
{
Files.createDirectories( path );
return Paths.get( loc );
}
else
{
return Paths.get( session.getLocalRepository().getBasedir() ).getParent().resolve( "build-cache" );
}
return path;
}

private Path remoteBuildPath( CacheContext context, String filename ) throws IOException
{
return buildCacheDir( context ).resolve( filename );
return remoteBuildDir( context ).resolve( filename );
}

private Path localBuildPath( CacheContext context, String filename, boolean createDir ) throws IOException
Expand All @@ -461,6 +470,11 @@ private Path localBuildPath( CacheContext context, String filename, boolean crea
return localBuildDir.resolve( filename );
}

private Path remoteBuildDir( CacheContext context ) throws IOException
{
return buildCacheDir( context ).resolve( cacheConfig.getId() );
}

private Path localBuildDir( CacheContext context ) throws IOException
{
return buildCacheDir( context ).resolve( "local" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public interface CacheConfig

int getMaxLocalBuildsCached();

String getLocalRepositoryLocation();

List<String> getAttachedOutputs();

boolean adjustMetaInfVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public CacheState initialize()
{
LOGGER.info( "Loading cache configuration from {}", configPath );
cacheConfig = xmlService.loadCacheConfig( configPath.toFile() );
fillWithDefaults( cacheConfig );
}
catch ( Exception e )
{
Expand Down Expand Up @@ -585,6 +584,13 @@ public int getMaxLocalBuildsCached()
return getLocal().getMaxBuildsCached();
}

@Override
public String getLocalRepositoryLocation()
{
checkInitializedState();
return getLocal().getLocation();
}

@Override
public List<String> getAttachedOutputs()
{
Expand Down
6 changes: 6 additions & 0 deletions src/main/mdo/build-cache-config.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ under the License.
<class>
<name>Local</name>
<fields>
<field>
<name>location</name>
<type>String</type>
<description>The base directory where the local cache is located.
Defaults to {@code $\{localRepository}/../cache}.</description>
</field>
<field>
<name>maxBuildsCached</name>
<type>int</type>
Expand Down

0 comments on commit 4794ac6

Please sign in to comment.