@Override public void setApplicationPath(String path) { getProjectConfiguration().setProperty(RestFacet.ROOTPATH, path); if (classPackage == null || className == null) { reportConfigurationError(className); } JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class); try { String classname = classPackage + "." + this.className; JavaResource javaResource = javaSourceFacet.getJavaResource(classname); if (!javaResource.exists()) { reportConfigurationError(classname); } javaResource .getJavaSource() .getAnnotation("javax.ws.rs.ApplicationPath") .setStringValue(path); } catch (FileNotFoundException e) { reportConfigurationError(className); } }
@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; }
@Command("new-class") public void newClassCommand( @Option(name = "interface", shortName = "i") String interfaceName, @Option(name = "implementation", shortName = "m", type = PromptType.JAVA_CLASS) String implName, PipeOut out) { ResourceFacet resourcesFacet = project.getFacet(ResourceFacet.class); JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class); try { JavaResource implementationFile = javaSourceFacet.getJavaResource(implName); if (!implementationFile.exists()) { out.println( "The implementation class " + implName + " does not exist in the current project. You can declare only existing implementations of " + interfaceName); return; } } catch (FileNotFoundException fnfe) { out.println( "The implementation class " + implName + " does not exist in the current project. You can declare only existing implementations of " + interfaceName); return; } DirectoryResource servicesDirectory = getServicesDirectory(resourcesFacet); UnknownFileResource implementationsFile = getImplementationsFile(interfaceName, servicesDirectory); try { String implementations = getImplementations(implementationsFile, implName) + implName; implementationsFile.setContents(implementations); } catch (IOException ioe) { out.println("Could not update " + implementationsFile + ". Reason: " + ioe.getMessage()); } catch (ImplementationExistsException iee) { out.println( "The implementation " + implName + " is already declared in " + implementationsFile + "."); } }