/**
   * 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();
  }
Beispiel #2
0
 /**
  * Returns the service source folders or an empty list
  *
  * @param projectRoot the root folder of the project
  * @param isMavenProject 'true' indicates the project is a maven project.
  * @return the service source folder
  */
 public static List<Folder> getSourceFolders(Folder projectRoot, boolean isMavenProject) {
   List<Folder> sourceFolders = new ArrayList<Folder>();
   Folder mainSourceFolder =
       projectRoot.getFolder(
           isMavenProject ? ProjectConstants.MAVEN_SRC_DIR : ProjectConstants.SRC_DIR);
   if (mainSourceFolder.exists()) {
     sourceFolders.add(mainSourceFolder);
   }
   Resources<Folder> serviceFolders = projectRoot.getFolder("services").list().folders();
   for (Folder serviceFolder : serviceFolders) {
     Folder serviceSourceFolder = serviceFolder.getFolder("src");
     if (serviceSourceFolder.exists()) {
       sourceFolders.add(serviceSourceFolder);
     }
   }
   return Collections.unmodifiableList(sourceFolders);
 }
  public String copyComponentServices(String path) {
    Folder componentFolder =
        this.fileSystem.getWaveMakerHomeFolder().getFolder("common/packages").getFolder(path);
    com.wavemaker.tools.io.Folder componentServicesFolder = componentFolder.getFolder("services");
    com.wavemaker.tools.io.Folder projectServicesFolder =
        this.serviceDeploymentManager
            .getProjectManager()
            .getCurrentProject()
            .getRootFolder()
            .getFolder("services");
    String responseInclude = "";
    String responseExclude = "";
    if (componentServicesFolder.exists()) {
      com.wavemaker.tools.io.Resources<com.wavemaker.tools.io.Folder> componentServiceFolders =
          componentServicesFolder.list().folders();
      for (com.wavemaker.tools.io.Folder f : componentServiceFolders) {
        String name = f.getName();
        com.wavemaker.tools.io.Folder projectServiceFolder = projectServicesFolder.getFolder(name);
        if (!projectServiceFolder.exists()) {
          projectServiceFolder.createIfMissing();
          f.copyContentsTo(projectServiceFolder);
          if (responseInclude.equals("") == false) responseInclude += ", ";
          responseInclude += "'" + name + "'";
        } else {
          if (responseExclude.equals("") == false) responseExclude += ", ";
          responseExclude += "'" + name + "'";
        }
      }
    }

    com.wavemaker.tools.io.Resources<com.wavemaker.tools.io.File> jarfiles =
        componentFolder.list().files().include(FilterOn.names().ending(".jar"));
    com.wavemaker.tools.io.Folder projectFolder =
        this.serviceDeploymentManager.getProjectManager().getCurrentProject().getRootFolder();
    com.wavemaker.tools.io.Folder libFolder = projectFolder.getFolder("lib");
    for (com.wavemaker.tools.io.File f : jarfiles) {
      com.wavemaker.tools.io.File destfile = libFolder.getFile(f.getName());
      if (!destfile.exists()) {
        f.copyTo(libFolder);
      }
    }

    return "{servicesAdded: [" + responseInclude + "], servicesSkipped: [" + responseExclude + "]}";
  }
 public void copyFolder(@ParamName(name = "from") String from, @ParamName(name = "to") String to)
     throws IOException {
   Folder source;
   if (from.startsWith("app/templates")) {
     source = this.fileSystem.getStudioWebAppRootFolder().getFolder(from);
   } else {
     source = getResource(from, Folder.class);
   }
   Folder dest = getResource(to, Folder.class);
   if (dest.exists()) throw new IOException("Already Exists");
   dest.createIfMissing();
   source.copyContentsTo(dest);
 }
 /**
  * Unzips the specifed file. The file will be unzip into a folder with the same name as the file.
  * The zip file will be deleted after unzip.
  *
  * @see #uploadFile(MultipartFile, String)
  * @return <tt>true</tt> if the file was unzipped.
  */
 public boolean unzipAndMoveNewFile(@ParamName(name = "file") String path) {
   File zipFile = getResource(path, File.class);
   String unpackName = zipFile.getName();
   if (unpackName.indexOf(".") != -1) {
     unpackName = unpackName.substring(0, unpackName.lastIndexOf("."));
   }
   if (zipFile.getParent().hasExisting(unpackName)) {
     unpackName = generateUniqueNumberedFileName(zipFile.getParent(), unpackName);
   }
   Folder unpackFolder = zipFile.getParent().getFolder(unpackName);
   ZipArchive.unpack(zipFile, unpackFolder);
   zipFile.delete();
   return unpackFolder.exists();
 }
  @Override
  public void doUpgrade(Project project, UpgradeInfo upgradeInfo) {

    Folder panesFolder = project.getWebAppRootFolder().getFolder(OLD_PANES_DIR);

    // if the project doesn't contain any panes, don't do the upgrade
    if (!panesFolder.exists()) {
      return;
    }
    panesFolder.rename("pages");

    upgradeInfo.addMessage(
        "Moved old "
            + OLD_PANES_DIR
            + " to new "
            + ProjectConstants.PAGES_DIR
            + "; static references to "
            + OLD_PANES_DIR
            + " will have to be updated");
  }
  public void processService(DesignServiceManager serviceMgr, String serviceId) {
    Folder serviceDir = serviceMgr.getServiceRuntimeFolder(serviceId);
    Folder serviceFolder = serviceMgr.getServiceRuntimeFolder(serviceId);
    if (!serviceFolder.exists()) {
      throw new BuildException("Could not locate service home for " + serviceId);
    }
    ServiceClassGenerator generator = new ServiceClassGenerator();
    Resources<File> files = getServiceFiles(serviceFolder);
    List<ServiceFile> serviceFiles = new ArrayList<ServiceFile>();
    for (File file : files) {
      File resource = serviceDir.getFile(file.getName());
      serviceFiles.add(new ServiceFile(file, resource));
    }
    generator.addServiceFiles(serviceFiles, serviceId);

    if (this.destDir == null) {
      generator.setOutputDirectory(serviceDir);
    } else {
      generator.setOutputDirectory(this.destDir);
    }

    generator.setDesignServiceManager(serviceMgr);
    generator.run();
  }
 /**
  * Create a new folder
  *
  * @param name the full name of the folder to create (including the path)
  * @return <tt>true</tt> if the folder was created
  */
 public boolean createFolder(@ParamName(name = "name") String name) {
   Folder folder = getResource(name, Folder.class);
   folder.createIfMissing();
   return folder.exists();
 }