jars-to-module-info-java.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash -e
  2. # Copyright 2017 Google Inc. All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Extracts the Java package names of all classes in the .jar files and writes a module-info.java
  16. # file to stdout that exports all of those packages.
  17. if [ -z "$1" ]; then
  18. echo "usage: $0 <module name> <jar1> [<jar2> ...]" >&2
  19. exit 1
  20. fi
  21. module_name=$1
  22. shift
  23. echo "module ${module_name} {"
  24. for j in "$@"; do zipinfo -1 $j ; done \
  25. | grep -E '/[^/]*\.class$' \
  26. | sed 's|\(.*\)/[^/]*\.class$| exports \1;|g' \
  27. | sed 's|/|.|g' \
  28. | sort -u
  29. echo "}"