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.º 2
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.º 3
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) {
     }
   }
 }
Ejemplo n.º 4
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 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);
    }
  }