Ejemplo n.º 1
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();
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  @HideFromClient
  private <T extends Resource> T getResource(String name, Class<T> resourceType) {
    Assert.notNull(name, "Name must not be null");
    Assert.notNull(resourceType, "ResourceType must not be null");

    Folder root;
    String resourceName;
    if (name.equals("/common")) {
      root = this.fileSystem.getCommonFolder();
      resourceName = "";
    } else if (name.startsWith("/common/")) {
      root = this.fileSystem.getCommonFolder();
      resourceName = name.substring("/common/".length());
    } else {
      root = this.projectManager.getCurrentProject().getRootFolder();
      resourceName = name;
    }

    if (resourceName.length() == 0) {
      Assert.isInstanceOf(resourceType, root);
      return (T) root;
    }

    return root.jail().get(resourceName, resourceType);
  }
Ejemplo n.º 3
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));
  }
Ejemplo n.º 4
0
 /**
  * Unzip the specified input stream into a folder.
  *
  * @param inputStream the input stream to unzip (this must contain zip contents)
  * @param destination the destination folder
  * @see #unpack(File)
  */
 public static void unpack(InputStream inputStream, Folder destination) {
   Assert.notNull(inputStream, "InputStream must not be null");
   Assert.notNull(destination, "Destination must not be null");
   destination.createIfMissing();
   ZipInputStream zip = new ZipInputStream(new BufferedInputStream(inputStream));
   try {
     InputStream noCloseZip = new NoCloseInputStream(zip);
     ZipEntry entry = zip.getNextEntry();
     while (entry != null) {
       if (entry.isDirectory()) {
         destination.getFolder(entry.getName()).createIfMissing();
       } else {
         destination.getFile(entry.getName()).getContent().write(noCloseZip);
       }
       entry = zip.getNextEntry();
     }
   } catch (IOException e) {
     throw new ResourceException(e);
   } finally {
     try {
       zip.close();
     } catch (IOException e) {
     }
   }
 }
  public FileUploadResponse uploadClientComponent(MultipartFile file) throws IOException {
    String fileName = file.getOriginalFilename();
    String className = fileName.substring(0, fileName.lastIndexOf(".zip"));
    FileUploadResponse ret = new FileUploadResponse();
    Folder componentStage =
        this.fileSystem
            .getWaveMakerHomeFolder()
            .getFolder("common/packages")
            .getFolder(CLIENT_COMPONENTS_STAGE);
    ZipArchive.unpack(file.getInputStream(), componentStage);
    com.wavemaker.tools.io.File jsFile =
        componentStage.getFile(className + "/" + className + ".js");
    if (!jsFile.exists()) {
      componentStage.delete();
      throw new IOException(jsFile.toString() + " not found");
    }
    String str = getClientComponentPackageString(jsFile);
    String packageStr = str.substring(0, str.lastIndexOf("." + className));

    Folder componentFolder =
        this.fileSystem
            .getWaveMakerHomeFolder()
            .getFolder(StringUtils.packageToSrcFilePath(packageStr));
    componentFolder.createIfMissing();
    componentFolder.list().delete(); // delete older version of the composite
    Folder zipFolder = componentStage.getFolder(className);
    zipFolder.copyContentsTo(componentFolder);
    this.deploymentManager.writeModuleToLibJs(packageStr + "." + className);
    componentStage.delete();
    ret.setPath(packageStr + "." + className);

    return ret;
  }
Ejemplo n.º 6
0
  /**
   * Generates service stubs.
   *
   * @throws GenerationException
   */
  @SuppressWarnings("deprecation")
  public void generate() throws GenerationException {

    preGeneration();

    JDefinedClass serviceCls = generateClass();

    preGenerateClassBody(serviceCls);

    generateClassJavadoc(serviceCls.javadoc());

    if (hasDefaultConstructor()) {
      JMethod defaultConst = generateDefaultConstructor(serviceCls);
      JBlock defaultConstBody = defaultConst.body();
      generateDefaultConstructorBody(defaultConstBody);
    }

    List<String> operationNames = this.serviceDefinition.getOperationNames();

    if (this.logger.isDebugEnabled()) {
      this.logger.debug("Generating service class with operations: " + operationNames);
    }

    for (int i = 0; i < operationNames.size(); i++) {
      String operationName = operationNames.get(i);
      List<ElementType> inputTypes = getInputTypes(operationName);
      generateOperationMethod(serviceCls, operationName, inputTypes, null);

      // add overloaded versions for this method
      int j = 0;
      List<List<ElementType>> overloadedVersions = getOverloadedVersions(operationName);
      for (List<ElementType> overloadedInputTypes : overloadedVersions) {
        generateOperationMethod(serviceCls, operationName, overloadedInputTypes, j++);
      }
    }

    postGenerateClassBody(serviceCls);

    try {
      Folder dir = this.configuration.getOutputDirectory();
      if (dir instanceof LocalFolder) {
        File dest = ((LocalFolder) dir).getLocalFile();
        this.codeModel.build(dest, dest, null);
      } else {
        File f = IOUtils.createTempDirectory("dataService_directory", null);
        this.codeModel.build(f, f, null);
        Folder folder = new LocalFolder(f);
        folder.copyContentsTo(this.configuration.getOutputDirectory());
        IOUtils.deleteRecursive(f);
      }
    } catch (IOException e) {
      throw new GenerationException("Unable to write service stub", e);
    }

    postGeneration();
  }
Ejemplo n.º 7
0
 /**
  * Uploads a file to the given path
  *
  * @param file the file contents being uploaded
  * @param path the path where the file should be uploaded
  * @return an upload response
  * @throws IOException
  * @see {@link #unzipAndMoveNewFile(String)}
  */
 public FileUploadResponse uploadFile(@ParamName(name = "file") MultipartFile file, String path)
     throws IOException {
   FileUploadResponse response = new FileUploadResponse();
   try {
     Folder folder = getResource(path, Folder.class);
     String filename = getSafeFilename(file.getOriginalFilename());
     folder.getFile(filename).getContent().write(file.getInputStream());
   } catch (Exception e) {
     response.setError(e.getMessage());
   }
   return response;
 }
Ejemplo n.º 8
0
 /**
  * Return a set of all currently known services. Services are found by checking every directory in
  * the project home for the service xml.
  *
  * @return
  */
 public SortedSet<String> getServiceIds() {
   SortedSet<String> serviceIds = new TreeSet<String>();
   Resources<Folder> childFolders = getServicesFolder().list().folders();
   for (Folder child : childFolders) {
     String serviceId = child.getName();
     File serviceDefXmlFile = getServiceDefXmlFile(serviceId);
     if (serviceDefXmlFile.exists()) {
       serviceIds.add(serviceId);
     }
   }
   return serviceIds;
 }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
 /**
  * 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();
 }
Ejemplo n.º 11
0
 private List<Hashtable<String, Object>> listChildren(Folder folder) {
   Resources<Resource> list = folder.list().include(FilterOn.nonHidden());
   List<Hashtable<String, Object>> children = new ArrayList<Hashtable<String, Object>>();
   for (Resource child : list) {
     children.add(asHashTable(child));
   }
   return children;
 }
Ejemplo n.º 12
0
  @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");
  }
Ejemplo n.º 13
0
 private String generateUniqueNumberedFileName(Folder folder, String name) {
   String ext = "";
   if (name.lastIndexOf(".") != -1) {
     ext = name.substring(name.lastIndexOf("."));
     name = name.substring(0, name.length() - ext.length());
   }
   for (int i = 0; true; i++) {
     String candidate = name + i + ext;
     if (!folder.hasExisting(candidate)) {
       return candidate;
     }
   }
 }
Ejemplo n.º 14
0
  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();
  }
Ejemplo n.º 15
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 + "]}";
  }
Ejemplo n.º 17
0
 private Resources<com.wavemaker.tools.io.File> getServiceFiles(Folder folder) {
   return folder.list().files().include(FilterOn.names().notEnding(".properties"));
 }
Ejemplo n.º 18
0
 /**
  * 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();
 }
  public void deployClientComponent(
      String className,
      String folder,
      String data,
      String[] services,
      String[] images,
      String[] html)
      throws IOException {
    deployClientComponent(className, folder, data);

    /* Take care of the services */
    Folder componentFolder = this.fileSystem.getWaveMakerHomeFolder().getFolder("common/packages");
    if (folder != null && folder.length() > 0) {

      String[] folderList = folder.split("\\.");
      for (String f : folderList) {
        componentFolder = componentFolder.getFolder(f);
      }
    }

    Folder componentServiceFolder = componentFolder.getFolder("services");
    componentServiceFolder.createIfMissing();
    componentServiceFolder.list().delete(); // delete any old services
    com.wavemaker.tools.io.Folder projectServicesFolder =
        this.serviceDeploymentManager
            .getProjectManager()
            .getCurrentProject()
            .getRootFolder()
            .getFolder("services");

    int i;
    for (i = 0; i < services.length; i++) {
      Folder destFolder = componentServiceFolder.getFolder(services[i]);
      destFolder.createIfMissing();
      projectServicesFolder.getFolder(services[i]).copyContentsTo(destFolder);
    }

    com.wavemaker.tools.io.Folder webappFolder =
        this.serviceDeploymentManager
            .getProjectManager()
            .getCurrentProject()
            .getRootFolder()
            .getFolder("webapproot");
    Folder compositeImagesFolder = componentFolder.getFolder("images");
    compositeImagesFolder.createIfMissing();
    for (i = 0; i < images.length; i++) {
      com.wavemaker.tools.io.File sourceFile = webappFolder.getFile(images[i]);
      sourceFile.copyTo(compositeImagesFolder);
    }

    Folder compositeHtmlFolder = componentFolder.getFolder("html");
    compositeHtmlFolder.createIfMissing();
    for (i = 0; i < html.length; i++) {
      com.wavemaker.tools.io.File sourceFile = webappFolder.getFile(html[i]);
      sourceFile.copyTo(compositeHtmlFolder);
    }
  }
Ejemplo n.º 20
0
 // cftempfix
 public Project(Folder projectRootFolder, String projectName) {
   super();
   this.projectRootFolder = projectRootFolder.jail();
   this.projectName = projectName;
   this.mavenProject = projectRootFolder.getFile(ProjectConstants.POM_XML).exists();
 }
Ejemplo n.º 21
0
 /**
  * Create a {@link InputStream} containing a zip representation of the given folder.
  *
  * @param folder the folder to compress
  * @param prefix an optional entry prefix. This allows a entries to be nested within a folder if
  *     required
  */
 public static InputStream compress(Folder folder, String prefix) {
   return compress(folder.find(), prefix);
 }