Skip to content

Remove modular requirements from module-info.java files as well #37

@mkoncek

Description

@mkoncek

Consider this file from Guava:

/*
 * Copyright (C) 2008 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/** Google Guava */
module com.google.common {
  requires java.logging;
  requires transitive com.google.common.util.concurrent.internal;
  requires static jdk.unsupported;
  requires static com.google.errorprone.annotations;
  requires static com.google.j2objc.annotations;
  requires static org.jspecify;

  exports com.google.common.annotations;
  exports com.google.common.base;
  exports com.google.common.cache;
  exports com.google.common.collect;
  exports com.google.common.escape;
  exports com.google.common.eventbus;
  exports com.google.common.graph;
  exports com.google.common.hash;
  exports com.google.common.html;
  exports com.google.common.io;
  exports com.google.common.math;
  exports com.google.common.net;
  exports com.google.common.primitives;
  exports com.google.common.reflect;
  exports com.google.common.util.concurrent;
  exports com.google.common.xml;
}

Currently this macro is used to remove annotations from the Java sources:

%java_remove_annotations guava guava-testlib -s \
  -p org[.]jspecify[.]annotations[.] \
  -p com[.]google[.]common[.]annotations[.] \
  -p com[.]google[.]errorprone[.]annotations[.] \
  -p com[.]google[.]j2objc[.]annotations[.] \

But it ignores the requirements listed in module-info.java file.
It would be nice if the tool could do that as well.
Issues to fix first:

  • New CLI option, ideally to be used concurrently with annotation / import removal.
  • Module names can be different from package names, but can also be the same and it would be convenient not have to specify them twice.
  • Consider which keywords to search for. Most often it will be requires but what about exports, uses, opens, provides?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions