use of com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardFacet in project google-cloud-intellij by GoogleCloudPlatform.
the class AppEngineWebSchemaProvider method getSchema.
@Override
public XmlFile getSchema(@NotNull @NonNls String url, @Nullable Module module, @NotNull PsiFile baseFile) {
if (module == null) {
return null;
}
if (url.startsWith("http://appengine.google.com/ns/")) {
AppEngineStandardFacet facet = AppEngineStandardFacet.getAppEngineFacetByModule(module);
if (facet != null) {
final File file = CloudSdkInternals.getInstance().getWebSchemeFile();
if (file == null) {
return null;
}
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
if (virtualFile != null) {
final PsiFile psiFile = PsiManager.getInstance(module.getProject()).findFile(virtualFile);
if (psiFile instanceof XmlFile) {
return (XmlFile) psiFile;
}
}
}
} else if (url.startsWith("http://java.sun.com/xml/ns/jdo/jdoconfig")) {
final PsiPackage jdoPackage = JavaPsiFacade.getInstance(module.getProject()).findPackage("javax.jdo");
final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
if (jdoPackage != null) {
for (PsiDirectory directory : jdoPackage.getDirectories(scope)) {
final PsiFile file = directory.findFile("jdoconfig_2_3.xsd");
if (file instanceof XmlFile) {
return (XmlFile) file;
}
}
}
}
return null;
}
use of com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardFacet in project google-cloud-intellij by GoogleCloudPlatform.
the class AppEngineForbiddenCodeInspection method checkFile.
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
final Project project = manager.getProject();
Module module = ModuleUtilCore.findModuleForPsiElement(file);
final AppEngineStandardFacet appEngineStandardFacet = AppEngineStandardFacet.getAppEngineFacetByModule(module);
if (appEngineStandardFacet == null) {
return null;
}
if (appEngineStandardFacet.getRuntimeJavaVersion().atLeast(JavaVersion.JAVA_1_8)) {
return null;
}
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final List<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>();
file.accept(new JavaRecursiveElementWalkingVisitor() {
CloudSdkInternals sdkInternals = CloudSdkInternals.getInstance();
@Override
public void visitDocComment(PsiDocComment comment) {
}
@Override
public void visitMethod(PsiMethod method) {
final PsiModifierList modifierList = method.getModifierList();
if (modifierList.hasModifierProperty(PsiModifier.NATIVE)) {
if (!isNativeMethodAllowed(method)) {
problems.add(manager.createProblemDescriptor(modifierList, "Native methods aren't allowed in App Engine application", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
super.visitMethod(method);
}
@Override
public void visitNewExpression(PsiNewExpression expression) {
final PsiJavaCodeReferenceElement classReference = expression.getClassReference();
if (classReference != null) {
final PsiElement resolved = classReference.resolve();
if (resolved instanceof PsiClass) {
final String qualifiedName = ((PsiClass) resolved).getQualifiedName();
if (qualifiedName != null && sdkInternals.isMethodInBlacklist(qualifiedName, "new")) {
final String message = "App Engine application should not create new instances of '" + qualifiedName + "' class";
problems.add(manager.createProblemDescriptor(classReference, message, isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
}
super.visitNewExpression(expression);
}
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final PsiElement element = methodExpression.resolve();
if (element instanceof PsiMethod) {
final PsiMethod method = (PsiMethod) element;
final PsiClass psiClass = method.getContainingClass();
if (psiClass != null) {
final String qualifiedName = psiClass.getQualifiedName();
final String methodName = method.getName();
if (qualifiedName != null && sdkInternals.isMethodInBlacklist(qualifiedName, methodName)) {
final String message = "AppEngine application should not call '" + StringUtil.getShortName(qualifiedName) + "" + methodName + "' method";
problems.add(manager.createProblemDescriptor(methodExpression, message, isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
}
super.visitMethodCallExpression(expression);
}
@Override
public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
final PsiElement resolved = reference.resolve();
if (resolved instanceof PsiClass) {
final PsiFile psiFile = resolved.getContainingFile();
if (psiFile != null) {
final VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null && !fileIndex.isInSource(virtualFile)) {
final List<OrderEntry> list = fileIndex.getOrderEntriesForFile(virtualFile);
for (OrderEntry entry : list) {
if (entry instanceof JdkOrderEntry) {
final String className = ClassUtil.getJVMClassName((PsiClass) resolved);
if (className != null && !sdkInternals.isClassInWhiteList(className)) {
problems.add(manager.createProblemDescriptor(reference, "Class '" + className + "' is not included in App Engine JRE White List", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
}
}
}
}
super.visitReferenceElement(reference);
}
});
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardFacet in project google-cloud-intellij by GoogleCloudPlatform.
the class AppEngineJavaeeSupportContributor method setupFrameworkSupport.
@Override
public void setupFrameworkSupport(JavaeeFrameworkSupportContributionModel model) {
AppEngineStandardFacet appEngineStandardFacet = model.getFacet(AppEngineStandardFacetType.ID);
if (appEngineStandardFacet == null) {
return;
}
if (appEngineStandardFacet.getRuntimeJavaVersion().equals(JavaVersion.JAVA_1_7)) {
setWebXmlServletVersion(model.getModule());
}
Artifact artifactToDeploy = model.getExplodedEarArtifact();
if (artifactToDeploy == null) {
artifactToDeploy = model.getExplodedWarArtifact();
}
if (artifactToDeploy != null) {
AppEngineStandardWebIntegration.getInstance().setupRunConfigurations(artifactToDeploy, model.getModule(), model.getRunConfiguration());
}
}
Aggregations