Esempio n. 1
0
    public void destroy() throws IOException {
      FileObject parent = dataFolder.getPrimaryFile().getParent();
      // First; delete all files except packages
      DataObject ch[] = dataFolder.getChildren();
      boolean empty = true;
      for (int i = 0; ch != null && i < ch.length; i++) {
        if (!ch[i].getPrimaryFile().isFolder()) {
          ch[i].delete();
        } else {
          empty = false;
        }
      }

      // If empty delete itself
      if (empty) {
        super.destroy();
      }

      // Second; delete empty super packages
      while (!parent.equals(root) && parent.getChildren().length == 0) {
        FileObject newParent = parent.getParent();
        parent.delete();
        parent = newParent;
      }
    }
Esempio n. 2
0
  /**
   * Scans the directory structure starting at root, looking for folders that are either empty or
   * contain files, adding them to the set.
   *
   * <p>
   *
   * @param children set to which nodes are added.
   * @param fo file object to examine.
   * @param root root of the package hierarchy.
   * @param query true to query for visibility of files.
   */
  private static void findVisiblePackages(
      Set<Node> children, FileObject fo, FileObject root, boolean query) {

    VisibilityQuery vq = VisibilityQuery.getDefault();
    if (query && !vq.isVisible(fo)) {
      return;
    }

    FileObject[] kids = fo.getChildren();
    boolean hasSubfolders = false;
    boolean hasFiles = false;
    for (int ii = 0; ii < kids.length; ii++) {
      if (!query || vq.isVisible(kids[ii])) {
        if (kids[ii].isFolder()) {
          findVisiblePackages(children, kids[ii], root, query);
          hasSubfolders = true;
        } else {
          hasFiles = true;
        }
      }
    }
    if (hasFiles || !hasSubfolders) {
      DataFolder df = DataFolder.findFolder(fo);
      PackageNode pn = new PackageNode(root, df);
      children.add(pn);
    }
  }
Esempio n. 3
0
    @Override
    protected void addNotify() {
      super.addNotify();

      Set<Node> children = new TreeSet<Node>();
      FileObject[] kids = sourceRoot.getChildren();
      boolean archive = FileUtil.isArchiveFile(sourceRoot);
      VisibilityQuery vq = VisibilityQuery.getDefault();
      for (int ii = 0; ii < kids.length; ii++) {
        if (archive || vq.isVisible(kids[ii])) {
          if (kids[ii].isFolder()) {
            findVisiblePackages(children, kids[ii], sourceRoot, !archive);
          } else {
            try {
              DataObject data = DataObject.find(kids[ii]);
              // For sorting, wrap a filter around the node.
              Node node = new SortableNode(data.getNodeDelegate());
              children.add(node);
            } catch (DataObjectNotFoundException donfe) {
              // in that case, ignore the file
            }
          }
        }
      }

      // Add the children to our own set (which should be empty).
      Node[] kidsArray = children.toArray(new Node[children.size()]);
      super.add(kidsArray);
    }
Esempio n. 4
0
  @Override
  @SuppressWarnings("unchecked")
  public TopComponent getTopComponent() {
    // Loading the multiview windows:
    FileObject multiviewsFolder = FileUtil.getConfigFile("skitmultiviews");
    FileObject[] kids = multiviewsFolder.getChildren();
    MultiViewDescription[] descriptionArray = new MultiViewDescription[kids.length];
    ArrayList<MultiViewDescription> listOfDescs = new ArrayList<MultiViewDescription>();

    for (FileObject kid : FileUtil.getOrder(Arrays.asList(kids), true)) {
      MultiViewDescription attribute = (MultiViewDescription) kid.getAttribute("multiview");

      if (attribute instanceof ContextAwareInstance) {
        Lookup lu = Lookups.fixed(this);
        attribute =
            ((ContextAwareInstance<MultiViewDescription>) attribute).createContextAwareInstance(lu);
      }

      listOfDescs.add(attribute);
    }

    for (int i = 0; i < listOfDescs.size(); i++) {
      descriptionArray[i] = listOfDescs.get(i);
    }

    CloneableTopComponent ctc =
        MultiViewFactory.createCloneableMultiView(descriptionArray, descriptionArray[0]);

    return ctc;
  }
  @Override
  public Set instantiate(ProgressHandle handle) throws IOException {
    handle.start(2);
    handle.progress(
        NbBundle.getMessage(
            JavaEESamplesWizardIterator.class,
            "LBL_NewSampleProjectWizardIterator_WizardProgress_CreatingProject"),
        1);

    Set resultSet = new LinkedHashSet();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty(WizardProperties.PROJ_DIR));
    String name = (String) wiz.getProperty(WizardProperties.NAME);
    FileObject template = Templates.getTemplate(wiz);

    FileObject dir = null;
    if ("web".equals(template.getAttribute("prjType"))) {
      // Use generator from web.examples to create project with specified name
      dir = WebSampleProjectGenerator.createProjectFromTemplate(template, dirF, name);
    } else {
      // Unzip prepared project only (no way to change name of the project)
      // FIXME: should be modified to create projects with specified name (project.xml files in
      // sub-projects should be modified too)
      // FIXME: web.examples and j2ee.samples modules may be merged into one module
      createFolder(dirF);
      dir = FileUtil.toFileObject(dirF);
      unZipFile(template.getInputStream(), dir);
      WebSampleProjectGenerator.configureServer(dir);
      for (FileObject child : dir.getChildren()) {
        WebSampleProjectGenerator.configureServer(child);
      }
    }

    ProjectManager.getDefault().clearNonProjectCache();
    handle.progress(
        NbBundle.getMessage(
            JavaEESamplesWizardIterator.class,
            "LBL_NewSampleProjectWizardIterator_WizardProgress_PreparingToOpen"),
        2);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration e = dir.getFolders(true);
    while (e.hasMoreElements()) {
      FileObject subfolder = (FileObject) e.nextElement();
      if (ProjectManager.getDefault().isProject(subfolder)) {
        resultSet.add(subfolder);
      }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
      ProjectChooser.setProjectsFolder(parent);
    }

    handle.finish();
    return resultSet;
  }
Esempio n. 6
0
 public Transferable paste() throws IOException {
   assert this.op != DnDConstants.ACTION_NONE;
   for (int ni = 0; ni < nodes.length; ni++) {
     FileObject fo = srcRoot;
     if (!nodes[ni].isDefaultPackage) {
       String pkgName = nodes[ni].getName();
       StringTokenizer tk = new StringTokenizer(pkgName, "."); // NOI18N
       while (tk.hasMoreTokens()) {
         String name = tk.nextToken();
         FileObject tmp = fo.getFileObject(name, null);
         if (tmp == null) {
           tmp = fo.createFolder(name);
         }
         fo = tmp;
       }
     }
     DataFolder dest = DataFolder.findFolder(fo);
     DataObject[] children = nodes[ni].dataFolder.getChildren();
     boolean cantDelete = false;
     for (int i = 0; i < children.length; i++) {
       if (children[i].getPrimaryFile().isData()
           && VisibilityQuery.getDefault().isVisible(children[i].getPrimaryFile())) {
         // Copy only the package level
         children[i].copy(dest);
         if (this.op == DnDConstants.ACTION_MOVE) {
           try {
             children[i].delete();
           } catch (IOException ioe) {
             cantDelete = true;
           }
         }
       } else {
         cantDelete = true;
       }
     }
     if (this.op == DnDConstants.ACTION_MOVE && !cantDelete) {
       try {
         FileObject tmpFo = nodes[ni].dataFolder.getPrimaryFile();
         FileObject originalRoot = nodes[ni].root;
         assert tmpFo != null && originalRoot != null;
         while (!tmpFo.equals(originalRoot)) {
           if (tmpFo.getChildren().length == 0) {
             FileObject tmpFoParent = tmpFo.getParent();
             tmpFo.delete();
             tmpFo = tmpFoParent;
           } else {
             break;
           }
         }
       } catch (IOException ioe) {
         // Not important
       }
     }
   }
   return ExTransferable.EMPTY;
 }
Esempio n. 7
0
  private void updateKeys() {
    List keys = new ArrayList();

    // Input and Output
    FileObject inputFO = mTestcaseDir.getFileObject("Input.xml"); // NOI18N
    if (inputFO != null) {
      keys.add(inputFO);
    }

    FileObject outputFO = mTestcaseDir.getFileObject("Output.xml"); // NOI18N
    if (outputFO != null) {
      keys.add(outputFO);
    }

    // Actual results
    FileObject realTestCaseResultsDir = getRealTestCaseResultsFolder();
    //        if (realTestCaseResultsDir != null) {
    //            if (realTestCaseResultsDir.getChildren().length > 0) {
    //                keys.add(realTestCaseResultsDir);
    //            }
    //        }
    //
    //        DataFolder dataFolder = DataFolder.findFolder(mTestCaseResultsDir);
    if (realTestCaseResultsDir != null) {
      FileObject[] resultFileObjects = realTestCaseResultsDir.getChildren();
      List resultKeys = new ArrayList();
      for (int i = 0; i < resultFileObjects.length; i++) {
        FileObject fo = resultFileObjects[i];
        if (isValidTestCaseResult(fo)) {
          resultKeys.add(fo);
        }
      }

      Collections.sort(
          resultKeys,
          new Comparator() {
            public int compare(Object obj1, Object obj2) {
              if ((obj1 instanceof FileObject) && (obj2 instanceof FileObject)) {
                FileObject fo1 = (FileObject) obj1;
                FileObject fo2 = (FileObject) obj2;

                return fo2.getNameExt().compareTo(fo1.getNameExt());
              } else {
                return 0;
              }
            }
          });

      keys.addAll(resultKeys);
    }

    setKeys(keys);
  }
Esempio n. 8
0
  /** Set up given number of FileObjects */
  protected FileObject[] setUpFileObjects(int foCount) throws Exception {
    tmp = createTempFolder();
    destFolder = LocalFSTest.createFiles(foCount, 0, tmp);
    File xmlbase =
        generateXMLFile(
            destFolder,
            new ResourceComposer(LocalFSTest.RES_NAME, LocalFSTest.RES_EXT, foCount, 0));
    xmlfs = new XMLFileSystem();
    xmlfs.setXmlUrl(xmlbase.toURL(), false);

    FileObject pkg = xmlfs.findResource(PACKAGE);
    return pkg.getChildren();
  }
Esempio n. 9
0
 /**
  * Check whether a package is empty (devoid of files except for subpackages).
  *
  * <p>
  *
  * @param fo file object to check.
  * @param recurse specifies whether to check if subpackages are empty too.
  */
 private static boolean isEmpty(FileObject fo, boolean recurse) {
   if (fo != null) {
     FileObject[] kids = fo.getChildren();
     for (int ii = 0; ii < kids.length; ii++) {
       if (!kids[ii].isFolder() && VisibilityQuery.getDefault().isVisible(kids[ii])) {
         return false;
       } else if (recurse && !isEmpty(kids[ii])) {
         return false;
       }
     }
   }
   return true;
 }
 /**
  * Get plugin names of baserCMS.
  *
  * @param baserModule {@link CakePhpModule}
  * @return plugin names
  */
 private List<String> getBaserPluginNames(CakePhpModule baserModule) {
   FileObject baserPluginDirectory = baserModule.getDirectory(DIR_TYPE.BASER_PLUGIN);
   if (baserPluginDirectory == null) {
     return Collections.emptyList();
   }
   FileObject[] children = baserPluginDirectory.getChildren();
   ArrayList<String> pluginNames = new ArrayList<String>(children.length);
   for (FileObject child : children) {
     if (!child.isFolder()) {
       continue;
     }
     pluginNames.add(child.getName());
   }
   return pluginNames;
 }
 private ClassPath getTestRunnerClassPath(TmcProjectInfo projectInfo) {
   FileObject projectDir = projectInfo.getProjectDir();
   FileObject testrunnerDir = projectDir.getFileObject("lib/testrunner");
   if (testrunnerDir != null) {
     FileObject[] files = testrunnerDir.getChildren();
     ArrayList<URL> urls = new ArrayList<URL>();
     for (FileObject file : files) {
       URL url = FileUtil.urlForArchiveOrDir(FileUtil.toFile(file));
       if (url != null) {
         urls.add(url);
       }
     }
     return ClassPathSupport.createClassPath(urls.toArray(new URL[0]));
   } else {
     return null;
   }
 }
Esempio n. 12
0
 private static void addPackages(
     final ClassPath classPath,
     final FileObject rootPackage,
     final boolean includeRootPackage,
     final Collection<JavaPackage> packCollection) {
   if (FileObjectUtils.isValidDir(rootPackage)) {
     final JavaPackage pack = new JavaPackage(classPath, rootPackage);
     if ((pack.isRoot() && includeRootPackage)
         || !pack.hasSubPackage()
         || pack.hasFileChildren()) {
       packCollection.add(pack);
     }
     for (FileObject subPkg : rootPackage.getChildren()) {
       addPackages(classPath, subPkg, includeRootPackage, packCollection);
     }
   }
 }
Esempio n. 13
0
 /**
  * Determines all files and folders that belong to a given project and adds them to the supplied
  * Collection.
  *
  * @param filteredFiles destination collection of Files
  * @param project project to examine
  */
 public static void addProjectFiles(
     Collection filteredFiles,
     Collection rootFiles,
     Collection rootFilesExclusions,
     Project project) {
   FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache();
   Sources sources = ProjectUtils.getSources(project);
   SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC);
   for (int j = 0; j < sourceGroups.length; j++) {
     SourceGroup sourceGroup = sourceGroups[j];
     FileObject srcRootFo = sourceGroup.getRootFolder();
     File rootFile = FileUtil.toFile(srcRootFo);
     try {
       getCVSRootFor(rootFile);
     } catch (IOException e) {
       // the folder is not under a versioned root
       continue;
     }
     rootFiles.add(rootFile);
     boolean containsSubprojects = false;
     FileObject[] rootChildren = srcRootFo.getChildren();
     Set projectFiles = new HashSet(rootChildren.length);
     for (int i = 0; i < rootChildren.length; i++) {
       FileObject rootChildFo = rootChildren[i];
       if (CvsVersioningSystem.FILENAME_CVS.equals(rootChildFo.getNameExt())) continue;
       File child = FileUtil.toFile(rootChildFo);
       // #67900 Added special treatment for .cvsignore files
       if (sourceGroup.contains(rootChildFo)
           || CvsVersioningSystem.FILENAME_CVSIGNORE.equals(rootChildFo.getNameExt())) {
         // TODO: #60516 deep scan is required here but not performed due to performace reasons
         projectFiles.add(child);
       } else {
         int status = cache.getStatus(child).getStatus();
         if (status != FileInformation.STATUS_NOTVERSIONED_EXCLUDED) {
           rootFilesExclusions.add(child);
           containsSubprojects = true;
         }
       }
     }
     if (containsSubprojects) {
       filteredFiles.addAll(projectFiles);
     } else {
       filteredFiles.add(rootFile);
     }
   }
 }
  private void loadFromWebServicesHome() {
    for (FileObject fo : getWebServiceHome().getChildren()) {
      if (!fo.isFolder()) {
        continue;
      }
      for (FileObject file : fo.getChildren()) {
        if (!file.getNameExt().endsWith("-saas.xml")) { // NOI18N

          continue;
        }
        try {
          loadSaasServiceFile(file, true);
        } catch (Exception ex) {
          Exceptions.printStackTrace(ex);
        }
      }
    }
  }
  @ForAllEnvironments
  public void testCyclicLinksRefresh() throws Exception {
    String baseDir = null;
    try {
      baseDir = mkTempAndRefreshParent(true);
      String selfLinkName = "link";
      String linkName1 = "link1";
      String linkName2 = "link2";
      String baseDirlinkName = "linkToDir";
      String script =
          "cd "
              + baseDir
              + "; "
              + "ln -s "
              + selfLinkName
              + ' '
              + selfLinkName
              + ";"
              + "ln -s "
              + linkName1
              + ' '
              + linkName2
              + ";"
              + "ln -s "
              + linkName2
              + ' '
              + linkName1
              + ";"
              + "ln -s "
              + baseDir
              + ' '
              + baseDirlinkName;
      ProcessUtils.ExitStatus res = ProcessUtils.execute(execEnv, "sh", "-c", script);
      assertEquals("Error executing script \"" + script + "\": " + res.error, 0, res.exitCode);

      FileObject baseDirFO = getFileObject(baseDir);
      baseDirFO.refresh();
      FileObject[] children =
          baseDirFO.getChildren(); // otherwise existent children are empty => refresh won't cycle
      baseDirFO.refresh();
    } finally {
      removeRemoteDirIfNotNull(baseDir);
    }
  }
 private void loadPresets() {
   FileObject folder = FileUtil.getConfigFile("layoutpresets");
   if (folder != null) {
     for (FileObject child : folder.getChildren()) {
       if (child.isValid() && child.hasExt("xml")) {
         try {
           InputStream stream = child.getInputStream();
           DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
           DocumentBuilder builder = factory.newDocumentBuilder();
           Document document = builder.parse(stream);
           Preset preset = new Preset(document);
           addPreset(preset);
         } catch (Exception ex) {
           ex.printStackTrace();
         }
       }
     }
   }
 }
Esempio n. 17
0
 /**
  * Returns true if the folder should be removed from the view i.e. it has some unignored children
  * and the children are folders only
  */
 private boolean toBeRemoved(FileObject folder) {
   boolean ignoredOnly = true;
   boolean foldersOnly = true;
   FileObject kids[] = folder.getChildren();
   for (int i = 0; i < kids.length; i++) {
     if (VisibilityQuery.getDefault().isVisible(kids[i])) {
       ignoredOnly = false;
       if (!kids[i].isFolder()) {
         foldersOnly = false;
         break;
       }
     }
   }
   if (ignoredOnly) {
     return false; // It is either empty or it only contains ignored files
     // thus is leaf and it means package
   } else {
     return foldersOnly;
   }
 }
 /** {@inheritDoc} */
 @Override
 public final Set<? extends Project> getSubprojects() {
   Set<Project> newProjects = new HashSet<Project>();
   FileObject dir = project.getProjectDirectory();
   if (dir != null) {
     for (FileObject childFolder : dir.getChildren()) {
       try {
         Project subp = ProjectManager.getDefault().findProject(childFolder);
         if (subp != null) {
           newProjects.add(subp);
         }
       } catch (IOException ex) {
         Exceptions.printStackTrace(ex);
       } catch (IllegalArgumentException ex) {
         // Do nothing
       }
     }
   }
   return Collections.unmodifiableSet(newProjects);
 }
 /**
  * Add elements to field for {@link PhpClass}.
  *
  * @param phpClass
  * @param helperDirectory
  */
 private void addElements(
     @NonNull PhpClass phpClass, FileObject targetDirectory, FILE_TYPE fileType) {
   if (targetDirectory == null) {
     return;
   }
   for (FileObject child : targetDirectory.getChildren()) {
     if (!FileUtils.isPhpFile(child)) {
       continue;
     }
     String fullName = child.getName();
     if (fileType == FILE_TYPE.HELPER && "AppHelper".equals(fullName)) { // NOI18N
       continue;
     }
     String name = fullName.replace(fileType.toString(), ""); // NOI18N
     if (fileType == FILE_TYPE.MODEL) {
       phpClass.addField(name, new PhpClass(name, name), child, 0);
     } else {
       phpClass.addField(name, new PhpClass(name, name + fileType.toString()), child, 0);
     }
   }
 }
Esempio n. 20
0
    private Collection<Key> getKeys() {

      if (groups != null) {
        // return Arrays.asList(groups);
        Collection<Key> groupList = new ArrayList<Key>();
        for (SourceGroup source : groups) {
          groupList.add(new Key(source.getRootFolder(), source));
        }
        return groupList;
      } else {
        FileObject files[] = fo.getChildren();
        Arrays.sort(files, new BrowseFolders.FileObjectComparator());
        ArrayList<Key> children = new ArrayList<Key>(files.length);
        /*
        if (BrowseFolders.this.target==org.openide.loaders.DataFolder.class)
        for( int i = 0; i < files.length; i++ ) {
        if ( files[i].isFolder() && group.contains( files[i] ) ) {
        children.add( new Key( files[i], group ) );
        }
        }*/
        // else {
        // add folders
        for (int i = 0; i < files.length; i++) {
          if (group.contains(files[i]) && files[i].isFolder()) {
            children.add(new Key(files[i], group));
          }
        }
        // add files
        for (int i = 0; i < files.length; i++) {
          if (group.contains(files[i]) && !files[i].isFolder()) {
            children.add(new Key(files[i], group));
          }
        }
        // }

        return children;
      }
    }
 private Properties parseRicohAdditionalResources(FileObject projectDir) {
   FileObject[] fos = projectDir.getChildren();
   for (int i = 0; i < fos.length; i++) {
     FileObject dalp = fos[i];
     if ("dalp".compareToIgnoreCase(dalp.getExt()) == 0) {
       Properties properties = new Properties();
       DalpParserHandlerImpl handler = new DalpParserHandlerImpl(projectDir, properties);
       try {
         DalpParser.parse(new InputSource(dalp.getInputStream()), handler);
       } catch (FileNotFoundException ex) {
         ErrorManager.getDefault().notify(ex);
       } catch (IOException ex) {
         ErrorManager.getDefault().notify(ex);
       } catch (SAXException ex) {
         ErrorManager.getDefault().notify(ex);
       } catch (ParserConfigurationException ex) {
         ErrorManager.getDefault().notify(ex);
       }
       return properties;
     }
   }
   return null;
 }
  private void loadFromDefaultFileSystem() {
    FileObject f = FileUtil.getConfigFile("SaaSServices"); // NOI18N

    if (f != null && f.isFolder()) {
      Enumeration<? extends FileObject> en = f.getFolders(false);
      while (en.hasMoreElements()) {
        FileObject groupFolder = en.nextElement();
        for (FileObject fo : groupFolder.getChildren()) {
          if (fo.isFolder()) {
            continue;
          }
          if (PROFILE_PROPERTIES_FILE.equals(fo.getNameExt())) {
            continue;
          }
          loadSaasServiceFile(fo, false);
        }
        SaasGroup g = rootGroup.getChildGroup(groupFolder.getName());
        if (g != null) {
          g.setIcon16Path((String) groupFolder.getAttribute("icon16"));
          g.setIcon32Path((String) groupFolder.getAttribute("icon32"));
        }
      }
    }
  }
  @ForAllEnvironments
  public void testDirectoryLink() throws Exception {
    String baseDir = null;
    try {
      baseDir = mkTempAndRefreshParent(true);

      String realDir = baseDir + "/real_dir";
      String linkDirName = "link_dir";
      String linkDir = baseDir + '/' + linkDirName;
      String realFile = realDir + "/file";
      String linkFile = linkDir + "/file";

      String script =
          "cd "
              + baseDir
              + "; "
              + "mkdir -p "
              + realDir
              + "; "
              + "ln -s "
              + realDir
              + ' '
              + linkDirName
              + "; "
              + "echo 123 > "
              + realFile;

      ProcessUtils.ExitStatus res = ProcessUtils.execute(execEnv, "sh", "-c", script);
      assertEquals("Error executing script \"" + script + "\": " + res.error, 0, res.exitCode);

      FileObject realFO, linkFO;

      realFO = getFileObject(realFile);
      linkFO = getFileObject(linkFile);

      assertTrue("FileObject should be writable: " + linkFO.getPath(), linkFO.canWrite());
      String content = "a quick brown fox...";
      writeFile(linkFO, content);
      WritingQueue.getInstance(execEnv).waitFinished(null);
      CharSequence readContent = readFile(realFO);
      assertEquals("File content differ", content.toString(), readContent.toString());

      FileObject linkDirFO = getFileObject(linkDir);
      FileObject[] children = linkDirFO.getChildren();
      for (FileObject child : children) {
        String childPath = child.getPath();
        String parentPath = linkDirFO.getPath();
        assertTrue(
            "Incorrect link child path: "
                + childPath
                + " should start with parent path "
                + parentPath,
            child.getPath().startsWith(parentPath));
      }
      FileObject linkFO2;
      linkFO2 = getFileObject(linkFile);
      assertTrue("Duplicate instances for " + linkFile, linkFO == linkFO2);
      linkDirFO.refresh();
      linkFO2 = getFileObject(linkFile);
      assertTrue("Duplicate instances for " + linkFile, linkFO == linkFO2);
    } finally {
      removeRemoteDirIfNotNull(baseDir);
    }
  }
Esempio n. 24
0
  private void doAnalysis() {
    if (project != null) {
      if (output.getIterations() != null) {
        if (!output.getIterations().isEmpty()) {
          numIterations = Integer.parseInt(output.getIterations());
        }
      } else {
        numIterations = NO_OF_ITERATIONS;
      }
      if (output.getOutputPath() != null) {
        String[] nlsprogressResult = null;
        String outputPath =
            project.getResultsFolder(true) + File.separator + output.getOutputPath();
        File outputFolder = new File(outputPath);
        if (outputFolder.exists()) {
          resultsfolder = FileUtil.toFileObject(outputFolder);
          if (resultsfolder.getChildren().length > 0) {
            try {
              resultsfolder =
                  FileUtil.createFolder(
                      resultsfolder.getParent(),
                      FileUtil.findFreeFolderName(
                          resultsfolder.getParent(), resultsfolder.getName()));
            } catch (IOException ex) {
              Exceptions.printStackTrace(ex);
            }
          }
        } else {
          try {
            FileUtil.createFolder(outputFolder);
            resultsfolder = outputFolder.exists() ? FileUtil.toFileObject(outputFolder) : null;
          } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
          }
        }

        datasets = getDatasets(datasetContainer);
        modelCalls.add(getModelCall(modelReference, 0));

        fitModelCall =
            getFitModelCall(datasets, modelCalls, modelDifferences, output, numIterations);

        if (isValidAnalysis(datasets, modelReference)) {
          timpcontroller = Lookup.getDefault().lookup(TimpControllerInterface.class);
          if (timpcontroller != null) {
            results = timpcontroller.runAnalysis(datasets, modelCalls, fitModelCall);
            nlsprogressResult =
                timpcontroller.getStringArray(
                    TimpControllerInterface.NAME_OF_RESULT_OBJECT + "$nlsprogress");
          }
        } else {
          // TODO: CoreErrorMessages warning
          return;
        }

        if (results != null) {
          writeResults(results, modelReference, nlsprogressResult);

        } else {
          try {
            writeSummary(
                resultsfolder,
                FileUtil.findFreeFileName(
                    resultsfolder, resultsfolder.getName() + "_errorlog", "summary"));
          } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
          }
        }
        timpcontroller.cleanup();
      }
    }
  }
Esempio n. 25
0
  @Override
  public List<String> getElements(int argCount, String filter) {
    CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule);
    if (cakeModule == null) {
      return Collections.emptyList();
    }
    CakeVersion version = cakeModule.getCakeVersion();
    if (version == null) {
      return Collections.emptyList();
    }
    int cakeVersion = version.getMajor();
    List<String> elements = new LinkedList<String>();
    if (type == null) {
      return elements;
    }

    if (argCount == 1) {
      String pluginName = null;
      boolean isPlugin = false;

      // CakePHP 2.x
      if (cakeVersion >= 2) {
        String[] split = filter.split("\\.", 2); // NOI18N
        int splitLength = split.length;

        // is plugin?
        if (splitLength > 0) {
          isPlugin = isPlugin(split[0]);
          if (isPlugin) {
            if (splitLength > 1) {
              filter = split[1];
            } else {
              filter = ""; // NOI18N
            }
            pluginName = split[0];
          }
        }
      }

      // check subdirectory
      filter = setSubDirectoryPath(filter);

      // add elements
      for (DIR_TYPE dirType : dirTypes) {
        if (!isPlugin) {
          if (PLUGINS.contains(dirType)) {
            continue;
          }
        }

        FileObject webrootDirectory =
            cakeModule.getDirectory(dirType, FILE_TYPE.WEBROOT, pluginName);
        if (webrootDirectory != null) {
          FileObject targetDirectory = null;
          if (filter.startsWith(SLASH)) {
            targetDirectory = webrootDirectory;
          } else {
            targetDirectory = webrootDirectory.getFileObject(getRelativePath());
          }
          if (targetDirectory != null) {
            for (FileObject element : targetDirectory.getChildren()) {
              addElement(element, filter, elements, pluginName);
            }
            break;
          }
        }
        if (isPlugin && !elements.isEmpty()) {
          return elements;
        }
      }

      if (!subDirectoryPath.isEmpty() || isPlugin) {
        return elements;
      }

      // plugin names
      // CakePHP 2.x
      if (cakeVersion >= 2) {
        for (DIR_TYPE dirType : PLUGINS) {
          FileObject pluginDirectory = cakeModule.getDirectory(dirType);
          if (pluginDirectory != null) {
            for (FileObject child : pluginDirectory.getChildren()) {
              if (child.isFolder()) {
                String name = child.getNameExt();
                FileObject webrootDirectory =
                    cakeModule.getDirectory(dirType, FILE_TYPE.WEBROOT, name);
                if (webrootDirectory != null
                    && webrootDirectory.getFileObject(type.toString()) != null) {
                  if (name.startsWith(filter)) {
                    name = name + DOT;
                    elements.add(name);
                  }
                }
              }
            }
          }
        }
      }
    }
    return elements;
  }
Esempio n. 26
0
    public void setName(String name) {
      PackageRenameHandler handler = getRenameHandler();
      if (handler != null) {
        handler.handleRename(this, name);
        return;
      }

      if (isDefaultPackage) {
        return;
      }
      String oldName = getName();
      if (oldName.equals(name)) {
        return;
      }
      if (!isValidPackageName(name)) {
        DialogDisplayer.getDefault()
            .notify(
                new NotifyDescriptor.Message(
                    NbBundle.getMessage(PackageViewChildren.class, "MSG_InvalidPackageName"),
                    NotifyDescriptor.INFORMATION_MESSAGE));
        return;
      }
      name = name.replace('.', '/') + '/'; // NOI18N
      oldName = oldName.replace('.', '/') + '/'; // NOI18N
      int i;
      for (i = 0; i < oldName.length() && i < name.length(); i++) {
        if (oldName.charAt(i) != name.charAt(i)) {
          break;
        }
      }
      i--;
      int index = oldName.lastIndexOf('/', i); // NOI18N
      String commonPrefix = index == -1 ? null : oldName.substring(0, index);
      String toCreate = (index + 1 == name.length()) ? "" : name.substring(index + 1); // NOI18N
      try {
        FileObject commonFolder =
            commonPrefix == null ? this.root : this.root.getFileObject(commonPrefix);
        FileObject destination = commonFolder;
        StringTokenizer dtk = new StringTokenizer(toCreate, "/"); // NOI18N
        while (dtk.hasMoreTokens()) {
          String pathElement = dtk.nextToken();
          FileObject tmp = destination.getFileObject(pathElement);
          if (tmp == null) {
            tmp = destination.createFolder(pathElement);
          }
          destination = tmp;
        }
        FileObject source = this.dataFolder.getPrimaryFile();
        DataFolder sourceFolder = DataFolder.findFolder(source);
        DataFolder destinationFolder = DataFolder.findFolder(destination);
        DataObject[] children = sourceFolder.getChildren();
        for (int j = 0; j < children.length; j++) {
          if (children[j].getPrimaryFile().isData()) {
            children[j].move(destinationFolder);
          }
        }
        while (!commonFolder.equals(source)) {
          if (source.getChildren().length == 0) {
            FileObject tmp = source;
            source = source.getParent();
            tmp.delete();
          } else {
            break;
          }
        }
      } catch (IOException ioe) {
        ErrorManager.getDefault().notify(ioe);
      }
    }