Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ $(call Executable_file,jurand_test): $(call Object_file,jurand_test.cpp)

manpages: \
$(call Manpage,jurand.1)\
$(call Manpage,java_remove_annotations.7)\
$(call Manpage,java_remove_imports.7)\

test-install: export buildroot = target/buildroot
test-install: export bindir = /usr/bin
test-install: export rpmmacrodir = /usr/lib/rpm/macros.d
test-install: export mandir = /usr/share/man
test-install: all manpages
./install.sh
Expand Down
9 changes: 6 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
= Jurand -- Java removal of annotations

A tool for manipulating symbols present in `.java` source files.
A tool for manipulating symbols present in Java source files.

The tool can be used for patching `.java` sources in cases where using `sed` is insufficient due to Java language syntax.
The tool can be used for patching Java sources in cases where using `sed` is insufficient due to Java language syntax.
The tool follows Java language rules rather than applying simple regular expressions on the source code.

Currently the tool is able to remove `import` statements and annotations.
Currently the tool is able to remove `import` statements, annotations and modular `requires` statements.

== Usage
----
Expand All @@ -16,6 +16,7 @@ Matcher::
[horizontal]
`-n <name>`::: Simple (not fully-qualified) class name.
`-p <pattern>`::: Regex pattern to match names used in code.
`-m <pattern>`::: Regex pattern to match module name `requires` fields used in `module-info.java` files.
[horizontal!]

Optional flags::
Expand All @@ -36,10 +37,12 @@ File path arguments are handled the following way:
* Symlinks are ignored
* Regular files are handled regardless of the file name
* Directories are traversed recursively and all `.java` files are handled
* Files named `module-info.java` are handled specifically

If no file path is provided then the tool reads from the standard input.

Class name matching can be done in two ways: `-n` to match simple class names or `-p` to match the provided regex pattern against fully qualified names as present in the sources.
Modular `requires` statements are matched using the `-m` flag provding a regex pattern.
These options can be specified multiple times.

The specific implementation of the regex search engine is subject to change.
Expand Down
1 change: 0 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ install_file()
}

install_file 755 "${bindir}" target/bin/jurand
install_file 644 "${rpmmacrodir}" macros/macros.jurand
install_file 644 "${mandir}" target/manpages/*
17 changes: 0 additions & 17 deletions macros/macros.jurand

This file was deleted.

81 changes: 0 additions & 81 deletions manpages/java_remove_annotations.7.adoc

This file was deleted.

82 changes: 0 additions & 82 deletions manpages/java_remove_imports.7.adoc

This file was deleted.

93 changes: 81 additions & 12 deletions manpages/jurand.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,40 @@
:manmanual: Jurand Manual

== NAME
jurand - Java removal of annotations
jurand - remove dependency declarations or annotations from Java source files

== SYNOPSIS
*jurand* [*-a*] [*-i*] [*-s*] [*-n*=_<name>_] [*-p*=<pattern>] [_<paths>_...]
*jurand* [*-i*] [*-s*] [*-a*] [*-n* _<name>_] [*-p|-m* _<pattern>_] [_<paths>_...]

== DESCRIPTION
A tool for manipulating symbols present in `.java` source files.
This tool removes annotations, corresponding *import* statements and modular *requires* statements from Java source files.

The tool can be used for patching `.java` sources in cases where using sed is insufficient due to Java language syntax.
The tool follows Java language rules rather than applying simple regular expressions on the source code.
The tool can be used for patching Java sources in cases where using sed is insufficient due to Java language syntax.
It follows Java language rules rather than applying simple regular expressions on the source code.

Currently the tool is able to remove `import` statements and annotations.
The tool matches all non-whitespace content following the 'import [static]' statement against all patterns provided via the *-p* flag and all simple class names against names provided by the *-n* flag.

In *module-info.java* files, all content following 'requires [static] [transitive]' is matched against all patterns provided via the *-m* flag.

File path arguments are handled the following way:

* Symlinks are ignored.
* Regular files are handled regardless of the file name.
* Directories are traversed recursively and all *.java* files are handled.
* Files named *module-info.java* are handled specifically.

Arguments can be specified in arbitrary order.

== OPTIONS
*-n*, *--name*=_<name>_::
*-n _<name>_::
Simple (not fully-qualified) class name.

*-p*, *--pattern*=_<pattern>_::
*-p _<pattern>_::
Regex pattern to match names used in code.

*-m _<pattern>_::
Regex pattern to match module name *requires* fields used in *module-info.java* files.

*-a*::
Also remove annotations used in code.

Expand All @@ -34,12 +48,67 @@ Replace the contents of files.
Fail if any of the specified options was redundant and no changes associated with the option were made.
This option is only applicable together with *-i*.

== EXAMPLES
Examples of usage in a *.spec* file:

- *jurand -i -s -a module-api module-impl module-tests -n Nullable*
- *jurand -i -s -a src -p org[.]jspecify[.]annotations -m org[.]jspecify*

=== Import patterns:
- Import statements present in Java source file:

1) import java.lang.Runnable;
2) import java.util.List;
3) import static java.util.*;
4) import static java.lang.String.valueOf;
5) import com.google.common.util.concurrent.Service;

- Names used to match:

Name 'Runnable' matches 1)
Name 'String' matches 4)

Name 'util' does not match anything.
Name '*' does not match anything.
Name 'valueOf' does not match anything.

- Patterns used to match:

Pattern 'Runnable' matches 1).
Pattern '[*]' matches 3).
Pattern 'java[.]util' matches 2), 3).
Pattern 'util' matches 2), 3), 5).
Patterns 'java', 'java.*' match 1) - 4).

Pattern 'static' does not match anything.

=== Annotations
- Annotations present in Java source file:

1) @SuppressWarnings
2) @SuppressFBWarnings(value = {"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
3) @org.junit.Test
4) @org.junit.jupiter.api.Test

- Names used to match:

Name 'SuppressWarnings' matches 1)
Name 'Test' matches 3), 4).

Name 'junit' does not match anything.

- Patterns used to match:

Pattern 'SuppressWarnings' matches 1).
Pattern 'Suppress' matches 1), 2).
Pattern 'org[.]junit[.]Test' matches 3).
Pattern 'junit' matches 3), 4).

Pattern '@SuppressWarnings' does not match anything.
Pattern 'EI_EXPOSE_REP' does not match anything.

== REPORTING BUGS
Bugs should be reported through the Jurand issue tracker at Github: https://github.com/fedora-java/jurand/issues.

== AUTHOR
Written by Marián Konček.

== SEE ALSO
*java_remove_annotations*(7),
*java_remove_imports*(7).
Loading