예제 #1
0
  private void deleteServiceShallow(String serviceId) throws IOException {
    Folder classesFolder = getProjectWebAppRoot().getFolder("WEB-INF/classes");
    File springConfig = classesFolder.getFile(serviceId + ".spring.xml");
    springConfig.delete();
    File dbProperty = classesFolder.getFile(serviceId + ".properties");
    if (dbProperty.exists()) {
      dbProperty.delete();
    }
    Service service = getService(serviceId);
    if (service != null) {
      com.wavemaker.tools.io.Resource target;
      if (service.getType().equals("JavaService")) {
        target = classesFolder.getFile(StringUtils.classNameToClassFilePath(service.getClazz()));
      } else {
        String packageName = StringUtils.getPackage(service.getClazz());
        target = classesFolder.getFolder(StringUtils.packageToSrcFilePath(packageName));
      }
      target.delete();
    }

    Map<String, Service> serviceDefs = getCurrentServiceDefinitions();
    serviceDefs.remove(serviceId);

    Folder serviceHome = getServiceFolder(serviceId);
    Project project = this.projectManager.getCurrentProject();
    project.deleteFile(serviceHome);
    project.deleteFile(ConfigurationCompiler.getSmdFile(project, serviceId));
  }
예제 #2
0
 private Hashtable<String, Object> asHashTable(Resource resource) {
   Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
   hashtable.put("file", resource.getName());
   hashtable.put("type", resource instanceof Folder ? "folder" : "file");
   if (resource instanceof File) {
     hashtable.put("modified", ((File) resource).getLastModified());
   }
   return hashtable;
 }
예제 #3
0
  /**
   * Rename a file or folder.
   *
   * @param from the source to rename, this will be a complete reference to a file or folder
   * @param to the destination name, this will be a complete reference to the new name (including
   *     path)
   * @param overwrite <tt>true</tt> if any existing destination should be overwritten. If this
   *     parameter is <tt>false</tt> a unique name should be generated based on <tt>to</tt>.
   * @return the name of the new file (excluding the path)
   */
  public String renameFile(
      @ParamName(name = "from") String from,
      @ParamName(name = "to") String to,
      @ParamName(name = "overwrite") boolean overwrite) {

    Resource source = getResource(from, Resource.class);

    ResourcePath destination = new ResourcePath().get(to);
    Folder destinationFolder = getResource(destination.getParent().toString(), Folder.class);
    Assert.state(
        destinationFolder.exists(),
        "The destination folder '" + destinationFolder + "' does not exist");

    String destinationName = destination.getName();
    if (destinationFolder.hasExisting(destinationName) && !overwrite) {
      destinationName = generateUniqueNumberedFileName(destinationFolder, destinationName);
    }

    Resource renamed = source;
    if (!destinationFolder.equals(renamed.getParent())) {
      renamed = renamed.moveTo(destinationFolder);
    }
    if (!renamed.getName().equals(destinationName)) {
      renamed = renamed.rename(destinationName);
    }
    return renamed.getName();
  }
예제 #4
0
 /**
  * Delete a file or folder
  *
  * @param name the complete path of the folder or file
  * @return <tt>true<tt> if the file/folder was deleted
  */
 public boolean deleteFile(@ParamName(name = "name") String name) {
   Resource resource = getResource(name, Resource.class);
   resource.delete();
   return !resource.exists();
 }