Fix issue that the forbidden-apis check do not always work (#6371)

* Fix the forbidden apis check do not work issue

* use SuppressForbidden annotation
This commit is contained in:
QiuMM 2018-09-27 00:39:39 +08:00 committed by Roman Leventov
parent 8978d3751b
commit 6843cbba1d
7 changed files with 18 additions and 8 deletions

View File

@ -19,6 +19,7 @@
package org.apache.druid.java.util.common; package org.apache.druid.java.util.common;
import io.netty.util.SuppressForbidden;
import org.joda.time.Chronology; import org.joda.time.Chronology;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
@ -40,6 +41,7 @@ public final class DateTimes
ISODateTimeFormat.dateTimeParser().withOffsetParsed() ISODateTimeFormat.dateTimeParser().withOffsetParsed()
); );
@SuppressForbidden(reason = "DateTimeZone#forID")
public static DateTimeZone inferTzfromString(String tzId) public static DateTimeZone inferTzfromString(String tzId)
{ {
try { try {
@ -65,6 +67,7 @@ public final class DateTimes
this.innerFormatter = innerFormatter.withChronology(ISOChronology.getInstanceUTC()); this.innerFormatter = innerFormatter.withChronology(ISOChronology.getInstanceUTC());
} }
@SuppressForbidden(reason = "DateTimeFormatter#parseDateTime")
public DateTime parse(final String instant) public DateTime parse(final String instant)
{ {
return innerFormatter.parseDateTime(instant); return innerFormatter.parseDateTime(instant);

13
pom.xml
View File

@ -931,15 +931,12 @@
<signaturesFile>${session.executionRootDirectory}/codestyle/joda-time-forbidden-apis.txt</signaturesFile> <signaturesFile>${session.executionRootDirectory}/codestyle/joda-time-forbidden-apis.txt</signaturesFile>
<signaturesFile>${session.executionRootDirectory}/codestyle/druid-forbidden-apis.txt</signaturesFile> <signaturesFile>${session.executionRootDirectory}/codestyle/druid-forbidden-apis.txt</signaturesFile>
</signaturesFiles> </signaturesFiles>
<excludes> <suppressAnnotations><annotation>**.SuppressForbidden</annotation></suppressAnnotations>
<exclude>org/apache/druid/java/util/common/DateTimes$UtcFormatter.class</exclude>
<exclude>org/apache/druid/java/util/common/DateTimes.class</exclude>
</excludes>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<id>validate</id> <id>compile</id>
<phase>validate</phase> <phase>compile</phase>
<goals> <goals>
<goal>check</goal> <goal>check</goal>
</goals> </goals>
@ -952,8 +949,8 @@
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
<id>testValidate</id> <id>testCompile</id>
<phase>validate</phase> <phase>test-compile</phase>
<goals> <goals>
<goal>testCheck</goal> <goal>testCheck</goal>
</goals> </goals>

View File

@ -36,6 +36,7 @@ import com.google.inject.Module;
import com.google.inject.name.Names; import com.google.inject.name.Names;
import io.airlift.airline.Command; import io.airlift.airline.Command;
import io.airlift.airline.Option; import io.airlift.airline.Option;
import io.netty.util.SuppressForbidden;
import org.apache.druid.collections.bitmap.BitmapFactory; import org.apache.druid.collections.bitmap.BitmapFactory;
import org.apache.druid.collections.bitmap.ConciseBitmapFactory; import org.apache.druid.collections.bitmap.ConciseBitmapFactory;
import org.apache.druid.collections.bitmap.ImmutableBitmap; import org.apache.druid.collections.bitmap.ImmutableBitmap;
@ -417,6 +418,7 @@ public class DumpSegment extends GuiceRunnable
return ImmutableList.copyOf(columnNames); return ImmutableList.copyOf(columnNames);
} }
@SuppressForbidden(reason = "System#out")
private <T> T withOutputStream(Function<OutputStream, T> f) throws IOException private <T> T withOutputStream(Function<OutputStream, T> f) throws IOException
{ {
if (outputFileName == null) { if (outputFileName == null) {

View File

@ -23,6 +23,7 @@ import com.google.inject.Injector;
import io.airlift.airline.Cli; import io.airlift.airline.Cli;
import io.airlift.airline.Help; import io.airlift.airline.Help;
import io.airlift.airline.ParseException; import io.airlift.airline.ParseException;
import io.netty.util.SuppressForbidden;
import org.apache.druid.cli.validate.DruidJsonValidator; import org.apache.druid.cli.validate.DruidJsonValidator;
import org.apache.druid.guice.ExtensionsConfig; import org.apache.druid.guice.ExtensionsConfig;
import org.apache.druid.guice.GuiceInjectors; import org.apache.druid.guice.GuiceInjectors;
@ -45,6 +46,7 @@ public class Main
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@SuppressForbidden(reason = "System#out")
public static void main(String[] args) public static void main(String[] args)
{ {
final Cli.CliBuilder<Runnable> builder = Cli.builder("druid"); final Cli.CliBuilder<Runnable> builder = Cli.builder("druid");

View File

@ -27,6 +27,7 @@ import com.google.common.collect.Sets;
import com.google.inject.Inject; import com.google.inject.Inject;
import io.airlift.airline.Command; import io.airlift.airline.Command;
import io.airlift.airline.Option; import io.airlift.airline.Option;
import io.netty.util.SuppressForbidden;
import org.apache.druid.guice.ExtensionsConfig; import org.apache.druid.guice.ExtensionsConfig;
import org.apache.druid.indexing.common.config.TaskConfig; import org.apache.druid.indexing.common.config.TaskConfig;
import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.ISE;
@ -414,6 +415,7 @@ public class PullDependencies implements Runnable
log.info("Finish downloading extension [%s]", versionedArtifact); log.info("Finish downloading extension [%s]", versionedArtifact);
} }
@SuppressForbidden(reason = "System#out")
private DefaultTeslaAether getAetherClient() private DefaultTeslaAether getAetherClient()
{ {
/* /*

View File

@ -20,6 +20,7 @@
package org.apache.druid.cli; package org.apache.druid.cli;
import io.airlift.airline.Command; import io.airlift.airline.Command;
import io.netty.util.SuppressForbidden;
import org.apache.druid.initialization.DruidModule; import org.apache.druid.initialization.DruidModule;
import org.apache.druid.initialization.Initialization; import org.apache.druid.initialization.Initialization;
import org.apache.druid.server.StatusResource; import org.apache.druid.server.StatusResource;
@ -31,6 +32,7 @@ import org.apache.druid.server.StatusResource;
public class Version implements Runnable public class Version implements Runnable
{ {
@Override @Override
@SuppressForbidden(reason = "System#out")
public void run() public void run()
{ {
System.out.println(new StatusResource.Status(Initialization.getLoadedImplementations(DruidModule.class))); System.out.println(new StatusResource.Status(Initialization.getLoadedImplementations(DruidModule.class)));

View File

@ -32,6 +32,7 @@ import com.google.inject.Injector;
import com.google.inject.name.Names; import com.google.inject.name.Names;
import io.airlift.airline.Command; import io.airlift.airline.Command;
import io.airlift.airline.Option; import io.airlift.airline.Option;
import io.netty.util.SuppressForbidden;
import org.apache.druid.cli.GuiceRunnable; import org.apache.druid.cli.GuiceRunnable;
import org.apache.druid.data.input.InputRow; import org.apache.druid.data.input.InputRow;
import org.apache.druid.data.input.impl.StringInputRowParser; import org.apache.druid.data.input.impl.StringInputRowParser;
@ -69,6 +70,7 @@ import java.util.List;
name = "validator", name = "validator",
description = "Validates that a given Druid JSON object is correctly formatted" description = "Validates that a given Druid JSON object is correctly formatted"
) )
@SuppressForbidden(reason = "System#out")
public class DruidJsonValidator extends GuiceRunnable public class DruidJsonValidator extends GuiceRunnable
{ {
private static final Logger LOG = new Logger(DruidJsonValidator.class); private static final Logger LOG = new Logger(DruidJsonValidator.class);