@Override public AstVisitor createJavaVisitor(@NonNull final JavaContext context) { return new ForwardingAstVisitor() { @Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); if (node.astName().toString().equals("sleep") && operand.toString().equals("Thread") && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, node, context.getLocation(node), "Don't call sleep. Use MockTimer instead."); } return super.visitMethodInvocation(node); } }; } }
/** * Determine the method names we are interested in for this check. * * @return a list representing the method names to check */ @Nullable @Override public List<String> getApplicableMethodNames() { return Collections.singletonList(CHECK_METHOD_TO_EXCLUDE); }
public static Collection< Artifact > filterArtifacts( @NonNull Iterable< Artifact > artifacts, final boolean skipDependencies, @Nullable final Collection< String > includeArtifactTypes, @Nullable final Collection< String > excludeArtifactTypes, @Nullable final Collection< String > includeArtifactQualifiers, @Nullable final Collection< String > excludeArtifactQualifiers )
@Override public AstVisitor createJavaVisitor(@NonNull final JavaContext context) { return new ForwardingAstVisitor() { @Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); if (node.astName().toString().equals("wait") && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, context.getLocation(node), "Don't wait on object. Use Timer's wait instead."); } return super.visitMethodInvocation(node); } }; } }
@Override public void error( @Nullable Throwable throwable, @Nullable String s, Object... objects ) { if ( ( throwable != null ) && ( s != null ) ) { final Formatter formatter = new Formatter(); log.error( formatter.format( s, objects ).out().toString(), throwable ); } else if ( ( throwable == null ) && ( s == null ) ) { // do nothing. } else if ( throwable != null ) { log.error( throwable ); } else { final Formatter formatter = new Formatter(); log.error( formatter.format( s, objects ).out().toString() ); } }
@Override public AstVisitor createJavaVisitor(@NonNull final JavaContext context) { return new ForwardingAstVisitor() { @Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); String methodName = node.astName().toString(); if (BAD_METHODS.contains(methodName) && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, context.getLocation(node), "Don't call " + methodName + " directly. Use" + " Timer instead."); } return super.visitMethodInvocation(node); } }; } }
public AndroidSdk( File sdkPath, String apiLevel, @Nullable String buildToolsVersion ) { this.sdkPath = sdkPath; this.buildToolsVersion = buildToolsVersion; this.progressIndicator = new ProgressIndicatorImpl(); if ( sdkPath != null ) { sdkManager = AndroidSdkHandler.getInstance( sdkPath ); platformToolsPath = new File( sdkPath, SdkConstants.FD_PLATFORM_TOOLS ); toolsPath = new File( sdkPath, SdkConstants.FD_TOOLS ); if ( sdkManager == null ) { throw invalidSdkException( sdkPath, apiLevel ); } } loadSDKToolsMajorVersion(); if ( apiLevel == null ) { apiLevel = DEFAULT_ANDROID_API_LEVEL; } androidTarget = findPlatformByApiLevel( apiLevel ); if ( androidTarget == null ) { throw invalidSdkException( sdkPath, apiLevel ); } }
@Override public AstVisitor createJavaVisitor(@NonNull final JavaContext context) { return new ForwardingAstVisitor() { @Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); String methodName = node.astName().toString(); if (BAD_METHODS.contains(methodName) && operand.toString().equals("System") && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, context.getLocation(node), "Don't call " + methodName + " on system. Use" + " Timer instead."); } return super.visitMethodInvocation(node); } }; } }
public MavenErrorReporter( ILogger logger, @NonNull EvaluationMode mode ) { super( mode ); this.logger = logger; }
private static ILogger createLogger(@NonNull StdLogger.Level level) { return new StdLogger(level); } }
private static File checkPath(@NonNull String path) throws FileNotFoundException { File file = new File(path); if (!file.exists()) { System.err.println(path + " does not exist"); throw new FileNotFoundException(path); } return file; }
@Override public void warning( @NonNull String s, Object... objects ) { final Formatter formatter = new Formatter(); log.warn( formatter.format( s, objects ).out().toString() ); }
@Override public void verbose( @NonNull String s, Object... objects ) { final Formatter formatter = new Formatter(); log.debug( formatter.format( s, objects ).out().toString() ); } }
@Override public void info( @NonNull String s, Object... objects ) { final Formatter formatter = new Formatter(); if ( verboseInfo ) { log.debug( formatter.format( s, objects ).out().toString() ); } else { log.info( formatter.format( s, objects ).out().toString() ); } }
@Override public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) { // 判断资源文件夹是否存在 Project project = context.getProject(); List<File> resourceFolder = project.getResourceFolders(); if (resourceFolder.isEmpty()) { return; } // 获取项目资源文件夹路径 String resourcePath = resourceFolder.get(0).getAbsolutePath(); // 获取 drawable 名字 String drawableName = attribute.getValue().replace("@drawable/", ""); try { // 若 drawable 为 Vector Drawable,则文件后缀为 xml,根据 resource 路径,drawable 名字,文件后缀拼接出完整路径 FileInputStream fileInputStream = new FileInputStream(resourcePath + "/drawable/" + drawableName + ".xml"); BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream)); String line = reader.readLine(); if (line.contains("vector")) { // 若文件存在,并且包含首行包含 vector,则为 Vector Drawable,抛出警告 context.report(ISSUE_XML_VECTOR_DRAWABLE, attribute, context.getLocation(attribute), attribute.getValue() + " 为 Vector Drawable,请使用 Vector 属性进行设置,避免 4.0 及以下版本的系统产生 Crash"); } fileInputStream.close(); } catch (Exception ignored) { } } }
@Override public void visitMethod(@NonNull JavaContext context, AstVisitor visitor, @NonNull MethodInvocation node) { VariableReference ref = (VariableReference) node.astOperand(); if (!"QMUILog".equals(ref.astIdentifier().astValue())) { return; } StrictListAccessor<Expression, MethodInvocation> args = node.astArguments(); if (args.isEmpty()) { return; } for (Expression expression : args) { String input = expression.toString(); if (input != null && input.contains("fuck")) { context.report( ISSUE_F_WORD, expression, context.getLocation(expression), "\uD83D\uDD95"); } } } }
protected void initializePublisher( @NonNull String packageName ) throws MojoExecutionException { getLog().debug( "Initializing publisher" ); if ( projectName == null || projectName.equals( "" ) ) { projectName = this.session.getCurrentProject().getName(); } try { AndroidPublisher publisher = AndroidPublisherHelper.init( projectName, publisherEmail, p12File ); edits = publisher.edits(); AndroidPublisher.Edits.Insert editRequest = edits.insert( packageName, null ); AppEdit edit = editRequest.execute(); editId = edit.getId(); } catch ( Exception e ) { throw new MojoExecutionException( e.getMessage(), e ); } }
private void publishApk( @NonNull String packageName ) throws MojoExecutionException { try { getLog().info( "Starting upload of apk " + apkFile.getAbsolutePath() ); FileContent newApkFile = new FileContent( AndroidPublisherHelper.MIME_TYPE_APK, apkFile ); Apk apk = edits.apks().upload( packageName, editId, newApkFile ).execute(); List<Integer> versionCodes = new ArrayList<Integer>(); versionCodes.add( apk.getVersionCode() ); Track newTrack = new Track().setVersionCodes( versionCodes ); edits.tracks().update( packageName, editId, track, newTrack ).execute(); publishWhatsNew( packageName, edits, editId, apk ); edits.commit( packageName, editId ).execute(); } catch ( Exception e ) { throw new MojoExecutionException( e.getMessage(), e ); } }