@@ -74,7 +74,7 @@ public void processRequest(List<String> args) throws Exception {
7474 }
7575
7676 /** Copy the resources */
77- copyResources (ops .resourceFiles , ops . resourceStripPrefix , tmpPath );
77+ copyResources (ops .resourceFiles , tmpPath );
7878
7979 /** Extract and copy resources from resource jars */
8080 copyResourceJars (ops .resourceJars , tmpPath );
@@ -313,44 +313,11 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc)
313313 }
314314 }
315315
316- private static void copyResources (
317- Map <String , Resource > resources , String resourceStripPrefix , Path dest ) throws IOException {
318- for (Entry <String , Resource > e : resources .entrySet ()) {
319- Path source = Paths .get (e .getKey ());
320- Resource resource = e .getValue ();
321- Path shortPath = Paths .get (resource .shortPath );
322- String dstr ;
323- // Check if we need to modify resource destination path
324- if (!"" .equals (resourceStripPrefix )) {
325- /**
326- * NOTE: We are not using the Resource Hash Value as the destination path when
327- * `resource_strip_prefix` present. The path in the hash value is computed by the
328- * `_adjust_resources_path` in `scala.bzl`. These are the default paths, ie, path that are
329- * automatically computed when there is no `resource_strip_prefix` present. But when
330- * `resource_strip_prefix` is present, we need to strip the prefix from the Source Path and
331- * use that as the new destination path Refer Bazel -> BazelJavaRuleClasses.java#L227 for
332- * details
333- */
334- dstr = getResourcePath (shortPath , resourceStripPrefix );
335- } else {
336- dstr = resource .destination ;
337- }
338-
339- if (dstr .charAt (0 ) == '/' ) {
340- // we don't want to copy to an absolute destination
341- dstr = dstr .substring (1 );
342- }
343- if (dstr .startsWith ("../" )) {
344- // paths to external repositories, for some reason, start with a leading ../
345- // we don't want to copy the resource out of our temporary directory, so
346- // instead we replace ../ with external/
347- // since "external" is a bit of reserved directory in bazel for these kinds
348- // of purposes, we don't expect a collision in the paths.
349- dstr = "external" + dstr .substring (2 );
350- }
351- Path target = dest .resolve (dstr );
352- File tfile = target .getParent ().toFile ();
353- tfile .mkdirs ();
316+ private static void copyResources (List <Resource > resources , Path dest ) throws IOException {
317+ for (Resource r : resources ) {
318+ Path source = Paths .get (r .source );
319+ Path target = dest .resolve (r .target );
320+ target .getParent ().toFile ().mkdirs ();
354321 Files .copy (source , target );
355322 }
356323 }
@@ -373,24 +340,6 @@ private static void copyClasspathResourcesToRoot(String[] classpathResourceFiles
373340 }
374341 }
375342
376- private static String getResourcePath (Path source , String resourceStripPrefix )
377- throws RuntimeException {
378- String sourcePath = source .toString ();
379- // convert strip prefix to a Path first and back to handle different file systems
380- String resourceStripPrefixPath = Paths .get (resourceStripPrefix ).toString ();
381- // check if the Resource file is under the specified prefix to strip
382- if (!sourcePath .startsWith (resourceStripPrefixPath )) {
383- // Resource File is not under the specified prefix to strip
384- throw new RuntimeException (
385- "Resource File "
386- + sourcePath
387- + " is not under the specified strip prefix "
388- + resourceStripPrefix );
389- }
390- String newResPath = sourcePath .substring (resourceStripPrefix .length ());
391- return newResPath ;
392- }
393-
394343 private static void copyResourceJars (String [] resourceJars , Path dest ) throws IOException {
395344 for (String jarPath : resourceJars ) {
396345 extractJar (jarPath , dest .toString (), null );
0 commit comments