Skip to content

Commit 7e4732d

Browse files
committed
Fix wagon transport when using webdav
1 parent d1322c6 commit 7e4732d

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ under the License.
139139
<version>3.0.2</version>
140140
<scope>compile</scope>
141141
</dependency>
142+
<dependency>
143+
<groupId>org.apache.maven.wagon</groupId>
144+
<artifactId>wagon-webdav-jackrabbit</artifactId>
145+
<version>3.5.1</version>
146+
</dependency>
142147
<dependency>
143148
<groupId>org.junit.jupiter</groupId>
144149
<artifactId>junit-jupiter-engine</artifactId>

src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.File;
2323
import java.io.IOException;
2424
import java.net.URI;
25+
import java.nio.file.Files;
2526
import java.nio.file.Path;
2627
import java.util.List;
2728
import java.util.Optional;
@@ -133,7 +134,7 @@ public void saveBuildInfo( CacheResult cacheResult, Build build )
133134
public void saveCacheReport( String buildId, MavenSession session, CacheReport cacheReport ) throws IOException
134135
{
135136
MavenProject rootProject = session.getTopLevelProject();
136-
final String resourceUrl = cacheConfig.getUrl() + "/" + MavenProjectInput.CACHE_IMPLEMENTATION_VERSION
137+
final String resourceUrl = MavenProjectInput.CACHE_IMPLEMENTATION_VERSION
137138
+ "/" + rootProject.getGroupId()
138139
+ "/" + rootProject.getArtifactId()
139140
+ "/" + buildId
@@ -159,14 +160,14 @@ public Optional<byte[]> getResourceContent( String url ) throws IOException
159160
{
160161
try
161162
{
162-
LOGGER.info( "Downloading {}", url );
163+
LOGGER.info( "Downloading {}", getFullUrl( url ) );
163164
GetTask task = new GetTask( new URI( url ) );
164165
transporter.get( task );
165166
return Optional.of( task.getDataBytes() );
166167
}
167168
catch ( Exception e )
168169
{
169-
LOGGER.info( "Cannot download {}", url, e );
170+
LOGGER.info( "Cannot download {}", getFullUrl( url ), e );
170171
return Optional.empty();
171172
}
172173
}
@@ -175,14 +176,14 @@ public boolean getResourceContent( String url, Path target ) throws IOException
175176
{
176177
try
177178
{
178-
LOGGER.info( "Downloading {}", url );
179+
LOGGER.info( "Downloading {}", getFullUrl( url ) );
179180
GetTask task = new GetTask( new URI( url ) ).setDataFile( target.toFile() );
180181
transporter.get( task );
181182
return true;
182183
}
183184
catch ( Exception e )
184185
{
185-
LOGGER.info( "Cannot download {}: {}", url, e.toString() );
186+
LOGGER.info( "Cannot download {}: {}", getFullUrl( url ), e.toString() );
186187
return false;
187188
}
188189
}
@@ -197,22 +198,28 @@ public String getResourceUrl( CacheContext context, String filename )
197198

198199
private String getResourceUrl( String filename, String groupId, String artifactId, String checksum )
199200
{
200-
return cacheConfig.getUrl() + "/" + MavenProjectInput.CACHE_IMPLEMENTATION_VERSION + "/" + groupId + "/"
201+
return MavenProjectInput.CACHE_IMPLEMENTATION_VERSION + "/" + groupId + "/"
201202
+ artifactId + "/" + checksum + "/" + filename;
202203
}
203204

204205
private void putToRemoteCache( byte[] bytes, String url ) throws IOException
205206
{
207+
Path tmp = Files.createTempFile( "mbce-", ".tmp" );
206208
try
207209
{
210+
Files.write( tmp, bytes );
208211
PutTask put = new PutTask( new URI( url ) );
209-
put.setDataBytes( bytes );
212+
put.setDataFile( tmp.toFile() );
210213
transporter.put( put );
211-
LOGGER.info( "Saved to remote cache {}", url );
214+
LOGGER.info( "Saved to remote cache {}", getFullUrl( url ) );
212215
}
213216
catch ( Exception e )
214217
{
215-
LOGGER.info( "Unable to save to remote cache {}", url, e );
218+
LOGGER.info( "Unable to save to remote cache {}", getFullUrl( url ), e );
219+
}
220+
finally
221+
{
222+
Files.deleteIfExists( tmp );
216223
}
217224
}
218225

@@ -223,11 +230,11 @@ private void putToRemoteCache( File file, String url ) throws IOException
223230
PutTask put = new PutTask( new URI( url ) );
224231
put.setDataFile( file );
225232
transporter.put( put );
226-
LOGGER.info( "Saved to remote cache {}", url );
233+
LOGGER.info( "Saved to remote cache {}", getFullUrl( url ) );
227234
}
228235
catch ( Exception e )
229236
{
230-
LOGGER.info( "Unable to save to remote cache {}", url, e );
237+
LOGGER.info( "Unable to save to remote cache {}", getFullUrl( url ), e );
231238
}
232239
}
233240

@@ -304,4 +311,9 @@ private Optional<CacheReport> findCacheInfo()
304311
return report;
305312
}
306313

314+
private String getFullUrl( String url )
315+
{
316+
return cacheConfig.getUrl() + "/" + url;
317+
}
318+
307319
}

0 commit comments

Comments
 (0)