@Override public boolean isInstalled() { JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class); Configuration projectConfiguration = getProjectConfiguration(); classPackage = projectConfiguration.getString(REST_APPLICATIONCLASS_PACKAGE); className = projectConfiguration.getString(REST_APPLICATIONCLASS_NAME); rootPath = projectConfiguration.getString(RestFacet.ROOTPATH); if ((classPackage == null || className == null) && !findApplicationClass()) { return false; } try { JavaResource javaResource = javaSourceFacet.getJavaResource(classPackage + "." + className); if (javaResource.exists() || findApplicationClass()) { return true; } } catch (FileNotFoundException e) { return false; } return false; }
private boolean findApplicationClass() { JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class); Configuration projectConfiguration = getProjectConfiguration(); projectConfiguration.clearProperty(REST_APPLICATIONCLASS_NAME); projectConfiguration.clearProperty(REST_APPLICATIONCLASS_PACKAGE); javaSourceFacet.visitJavaSources( new JavaResourceVisitor() { Configuration configuration = getProjectConfiguration(); boolean found = false; @Override public void visit(JavaResource javaResource) { if (!found) { try { if (javaResource.getJavaSource().getAnnotation("javax.ws.rs.ApplicationPath") != null) { configuration.setProperty( REST_APPLICATIONCLASS_PACKAGE, javaResource.getJavaSource().getPackage()); configuration.setProperty( REST_APPLICATIONCLASS_NAME, javaResource.getJavaSource().getName()); configuration.setProperty( RestFacet.ROOTPATH, javaResource .getJavaSource() .getAnnotation("javax.ws.rs.ApplicationPath") .getStringValue()); found = true; } } catch (FileNotFoundException e) { throw new RuntimeException(e); } } } }); return projectConfiguration.getString(REST_APPLICATIONCLASS_NAME) != null; }