Skip to content

Commit

Permalink
add Guice module for providing ScanResult from ClassGraph.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 320290436
Change-Id: I9eb0dc02fe06a1057cad4cafbcae3b003295338b
  • Loading branch information
magl0 authored and copybara-github committed Jul 8, 2020
1 parent e7f68dd commit 18d52f5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2020 Google LLC
*
* 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.
*/
package com.google.tsunami.common.reflection;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.inject.AbstractModule;
import io.github.classgraph.ScanResult;

/** Guice module for providing ClassGraph bindings. */
public final class ClassGraphModule extends AbstractModule {
private final ScanResult scanResult;

public ClassGraphModule(ScanResult scanResult) {
this.scanResult = checkNotNull(scanResult);
}

@Override
protected void configure() {
bind(ScanResult.class).annotatedWith(RuntimeClassGraphScanResult.class).toInstance(scanResult);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2020 Google LLC
*
* 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.
*/
package com.google.tsunami.common.reflection;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;

/** Annotation for the ClassGraph {@link io.github.classgraph.ScanResult} at runtime. */
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({PARAMETER, METHOD, FIELD})
public @interface RuntimeClassGraphScanResult {}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.tsunami.common.config.YamlConfigLoader;
import com.google.tsunami.common.io.archiving.GoogleCloudStorageArchiverModule;
import com.google.tsunami.common.net.http.HttpClientModule;
import com.google.tsunami.common.reflection.ClassGraphModule;
import com.google.tsunami.common.time.SystemUtcClockModule;
import com.google.tsunami.main.cli.option.ScanTargetCliOptions;
import com.google.tsunami.plugin.PluginExecutionModule;
Expand Down Expand Up @@ -107,6 +108,7 @@ private static final class TsunamiCliModule extends AbstractModule {

@Override
protected void configure() {
install(new ClassGraphModule(classScanResult));
install(new ConfigModule(classScanResult, tsunamiConfig));
install(new CliOptionsModule(classScanResult, "TsunamiCli", args));
install(new SystemUtcClockModule());
Expand Down

0 comments on commit 18d52f5

Please sign in to comment.