public PluginsEnvironmentBuilder(File dir) throws Exception {
    DirectoryScanner directoryScanner = new DirectoryScanner();

    directoryScanner.setBasedir(dir);
    directoryScanner.setIncludes(new String[] {"**\\liferay-plugin-package.properties"});

    directoryScanner.scan();

    String dirName = dir.getCanonicalPath();

    for (String fileName : directoryScanner.getIncludedFiles()) {
      setupWarProject(dirName, fileName);
    }

    directoryScanner = new DirectoryScanner();

    directoryScanner.setBasedir(dir);
    directoryScanner.setIncludes(new String[] {"**\\build.xml"});

    directoryScanner.scan();

    for (String fileName : directoryScanner.getIncludedFiles()) {
      String content = _fileUtil.read(dirName + "/" + fileName);

      boolean osgiProject = false;

      if (content.contains("<import file=\"../../build-common-osgi-plugin.xml\" />")
          || content.contains("../tools/sdk/build-common-osgi-plugin.xml\" />")) {

        osgiProject = true;
      }

      boolean sharedProject = false;

      if (content.contains("<import file=\"../build-common-shared.xml\" />")
          || content.contains("../tools/sdk/build-common-shared.xml\" />")) {

        sharedProject = true;
      }

      List<String> dependencyJars = Collections.emptyList();

      if (osgiProject) {
        int x = content.indexOf("osgi.ide.dependencies");

        if (x != -1) {
          x = content.indexOf("value=\"", x);
          x = content.indexOf("\"", x);

          int y = content.indexOf("\"", x + 1);

          dependencyJars = Arrays.asList(StringUtil.split(content.substring(x + 1, y)));
        }
      }

      if (osgiProject || sharedProject) {
        setupJarProject(dirName, fileName, dependencyJars, sharedProject);
      }
    }
  }
 private String[] findJsonFiles(File targetDirectory) {
   DirectoryScanner scanner = new DirectoryScanner();
   scanner.setIncludes(new String[] {"**/*.json"});
   scanner.setBasedir(targetDirectory);
   scanner.scan();
   return scanner.getIncludedFiles();
 }
예제 #3
0
  private DirectoryScanner scan(FileSet fileSet) {
    File basedir = new File(fileSet.getDirectory());

    if (!basedir.exists() || !basedir.isDirectory()) {
      return null;
    }

    DirectoryScanner scanner = new DirectoryScanner();

    List<String> includesList = fileSet.getIncludes();
    List<String> excludesList = fileSet.getExcludes();

    if (includesList.size() > 0) {
      scanner.setIncludes(includesList.toArray(new String[0]));
    }

    if (excludesList.size() > 0) {
      scanner.setExcludes(excludesList.toArray(new String[0]));
    }

    if (true) // fileSet.isUseDefaultExcludes() )
    {
      scanner.addDefaultExcludes();
    }

    scanner.setBasedir(basedir);
    scanner.setFollowSymlinks(true); // fileSet.isFollowSymlinks() );

    scanner.scan();

    return scanner;
  }
 /** Converts the file(s) identified by the given pattern. */
 public static void convert(String pattern, boolean compress) throws IOException {
   DirectoryScanner scanner = new DirectoryScanner();
   scanner.setBasedir(".");
   scanner.setIncludes(new String[] {pattern});
   scanner.scan();
   for (String source : scanner.getIncludedFiles()) {
     try {
       convert(source, source, compress);
     } catch (IOException e) {
       log.warning("Error converting file.", "file", source, e);
     }
   }
 }
 private String[] findJsonFiles(
     File targetDirectory, String fileIncludePattern, String fileExcludePattern) {
   DirectoryScanner scanner = new DirectoryScanner();
   if (fileIncludePattern == null || fileIncludePattern.isEmpty()) {
     scanner.setIncludes(new String[] {DEFAULT_FILE_INCLUDE_PATTERN});
   } else {
     scanner.setIncludes(new String[] {fileIncludePattern});
   }
   if (fileExcludePattern != null) {
     scanner.setExcludes(new String[] {fileExcludePattern});
   }
   scanner.setBasedir(targetDirectory);
   scanner.scan();
   return scanner.getIncludedFiles();
 }
  protected List<String> getFileNames(String basedir, String[] excludes, String[] includes) {

    DirectoryScanner directoryScanner = new DirectoryScanner();

    directoryScanner.setBasedir(basedir);

    if (_excludes != null) {
      excludes = ArrayUtil.append(excludes, _excludes);
    }

    directoryScanner.setExcludes(excludes);

    directoryScanner.setIncludes(includes);

    return sourceFormatterHelper.scanForFiles(directoryScanner);
  }
  public ExtInfoBuilder(String basedir, String outputDir, String servletContextName)
      throws Exception {

    DirectoryScanner ds = new DirectoryScanner();

    ds.setBasedir(basedir);
    ds.setExcludes(
        new String[] {
          ".svn/**",
          "**/.svn/**",
          "ext-impl/ext-impl.jar",
          "ext-impl/src/**",
          "ext-service/ext-service.jar",
          "ext-service/src/**",
          "ext-util-bridges/ext-util-bridges.jar",
          "ext-util-bridges/src/**",
          "ext-util-java/ext-util-java.jar",
          "ext-util-java/src/**",
          "ext-util-taglib/ext-util-taglib.jar",
          "ext-util-taglib/src/**",
          "liferay-plugin-package.properties"
        });

    ds.scan();

    String[] files = ds.getIncludedFiles();

    Arrays.sort(files);

    Element rootElement = new ElementImpl(DocumentHelper.createElement("ext-info"));

    Document document = new DocumentImpl(DocumentHelper.createDocument());

    document.setRootElement(rootElement);

    DocUtil.add(rootElement, "servlet-context-name", servletContextName);

    Element filesElement = rootElement.addElement("files");

    for (String file : files) {
      DocUtil.add(
          filesElement, "file", StringUtil.replace(file, StringPool.BACK_SLASH, StringPool.SLASH));
    }

    _fileUtil.write(outputDir + "/ext-" + servletContextName + ".xml", document.formattedString());
  }
예제 #8
0
  private Collection<Violation> parseReportIn(
      final String baseDir, final SwiftLintReportParser parser) {

    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setIncludes(new String[] {reportPath()});
    scanner.setBasedir(baseDir);
    scanner.setCaseSensitive(false);
    scanner.scan();
    String[] files = scanner.getIncludedFiles();

    Collection<Violation> result = new ArrayList<Violation>();
    for (String filename : files) {
      LOGGER.info("Processing SwiftLint report {}", filename);
      result.addAll(parser.parseReport(new File(filename)));
    }

    return result;
  }
예제 #9
0
  /**
   * Protected method for simplyfied addinng of mapped files
   *
   * @param file file to add
   * @param baseDir base directory for file
   */
  protected void addMappedFile(File file, File baseDir) {
    if (file.isFile()) {
      if (baseDir == null) {
        baseDir = file.getParentFile();
      }
      MappedFile mappedFile = new MappedFile();
      mappedFile.setFrom(file);
      String filename = file.getName();

      String[] names = getMapper().mapFileName(filename);
      // we don't use original filename if no mapping is available
      if (names == null || names.length == 0) {
        return;
      }

      File newFile = new File(file.getParent() + System.getProperty("file.separator") + names[0]);
      if (getDestDir() != null) {
        try {
          newFile =
              new File(
                  newFile
                      .getCanonicalPath()
                      .replace(baseDir.getCanonicalPath(), getDestDir().getCanonicalPath()));
        } catch (IOException ex) {
          log("Couldn't map file", ex, Project.MSG_WARN);
          return;
        }
      }
      mappedFile.setTo(newFile);
      mappedFiles.add(mappedFile);
    } else if (file.isDirectory()) {
      if (baseDir == null) {
        baseDir = file;
      }
      DirectoryScanner ds = new DirectoryScanner();
      ds.setBasedir(file);
      ds.scan();

      for (String fileName : ds.getIncludedFiles()) {
        addMappedFile(new File(file + System.getProperty("file.separator") + fileName), baseDir);
      }
    }
  }
  private void _collectSassFiles(List<String> fileNames, String dirName, String docrootDirName)
      throws Exception {

    DirectoryScanner directoryScanner = new DirectoryScanner();

    String basedir = docrootDirName.concat(dirName);

    directoryScanner.setBasedir(basedir);

    directoryScanner.setExcludes(
        new String[] {
          "**\\_*.scss",
          "**\\_diffs\\**",
          "**\\.sass-cache*\\**",
          "**\\.sass_cache_*\\**",
          "**\\_sass_cache_*\\**",
          "**\\_styled\\**",
          "**\\_unstyled\\**",
          "**\\css\\aui\\**",
          "**\\tmp\\**"
        });
    directoryScanner.setIncludes(new String[] {"**\\*.css", "**\\*.scss"});

    directoryScanner.scan();

    String[] fileNamesArray = directoryScanner.getIncludedFiles();

    if (!_isModified(basedir, fileNamesArray)) {
      return;
    }

    for (String fileName : fileNamesArray) {
      if (fileName.contains("_rtl")) {
        continue;
      }

      fileNames.add(_normalizeFileName(dirName, fileName));
    }
  }
예제 #11
0
  public JavadocFormatter(String[] args) throws Exception {
    Map<String, String> arguments = ArgumentsUtil.parseArguments(args);

    String init = arguments.get("javadoc.init");

    if (Validator.isNotNull(init) && !init.startsWith("$")) {
      _initializeMissingJavadocs = GetterUtil.getBoolean(init);
    }

    _inputDir = GetterUtil.getString(arguments.get("javadoc.input.dir"));

    if (_inputDir.startsWith("$")) {
      _inputDir = "./";
    }

    if (!_inputDir.endsWith("/")) {
      _inputDir += "/";
    }

    System.out.println("Input directory is " + _inputDir);

    String limit = arguments.get("javadoc.limit");

    _outputFilePrefix = GetterUtil.getString(arguments.get("javadoc.output.file.prefix"));

    if (_outputFilePrefix.startsWith("$")) {
      _outputFilePrefix = "javadocs";
    }

    String update = arguments.get("javadoc.update");

    if (Validator.isNotNull(update) && !update.startsWith("$")) {
      _updateJavadocs = GetterUtil.getBoolean(update);
    }

    DirectoryScanner directoryScanner = new DirectoryScanner();

    directoryScanner.setBasedir(_inputDir);
    directoryScanner.setExcludes(new String[] {"**\\classes\\**", "**\\portal-client\\**"});

    List<String> includes = new ArrayList<String>();

    if (Validator.isNotNull(limit) && !limit.startsWith("$")) {
      System.out.println("Limit on " + limit);

      String[] limitArray = StringUtil.split(limit, '/');

      for (String curLimit : limitArray) {
        includes.add("**\\" + StringUtil.replace(curLimit, ".", "\\") + "\\**\\*.java");
        includes.add("**\\" + curLimit + ".java");
      }
    } else {
      includes.add("**\\*.java");
    }

    directoryScanner.setIncludes(includes.toArray(new String[includes.size()]));

    directoryScanner.scan();

    String[] fileNames = directoryScanner.getIncludedFiles();

    if ((fileNames.length == 0) && Validator.isNotNull(limit) && !limit.startsWith("$")) {

      StringBundler sb = new StringBundler("Limit file not found: ");

      sb.append(limit);

      if (limit.contains(".")) {
        sb.append(" Specify limit filename without package path or ");
        sb.append("file type suffix.");
      }

      System.out.println(sb.toString());
    }

    _languagePropertiesFile = new File("src/content/Language.properties");

    if (_languagePropertiesFile.exists()) {
      _languageProperties = new Properties();

      _languageProperties.load(new FileInputStream(_languagePropertiesFile.getAbsolutePath()));
    }

    for (String fileName : fileNames) {
      fileName = StringUtil.replace(fileName, "\\", "/");

      _format(fileName);
    }

    for (Map.Entry<String, Tuple> entry : _javadocxXmlTuples.entrySet()) {
      Tuple tuple = entry.getValue();

      File javadocsXmlFile = (File) tuple.getObject(1);
      String oldJavadocsXmlContent = (String) tuple.getObject(2);
      Document javadocsXmlDocument = (Document) tuple.getObject(3);

      Element javadocsXmlRootElement = javadocsXmlDocument.getRootElement();

      javadocsXmlRootElement.sortElementsByChildElement("javadoc", "type");

      String newJavadocsXmlContent = javadocsXmlDocument.formattedString();

      if (!oldJavadocsXmlContent.equals(newJavadocsXmlContent)) {
        _fileUtil.write(javadocsXmlFile, newJavadocsXmlContent);
      }

      _detachUnnecessaryTypes(javadocsXmlRootElement);

      File javadocsRuntimeXmlFile =
          new File(StringUtil.replaceLast(javadocsXmlFile.toString(), "-all.xml", "-rt.xml"));

      String oldJavadocsRuntimeXmlContent = StringPool.BLANK;

      if (javadocsRuntimeXmlFile.exists()) {
        oldJavadocsRuntimeXmlContent = _fileUtil.read(javadocsRuntimeXmlFile);
      }

      String newJavadocsRuntimeXmlContent = javadocsXmlDocument.compactString();

      if (!oldJavadocsRuntimeXmlContent.equals(newJavadocsRuntimeXmlContent)) {

        _fileUtil.write(javadocsRuntimeXmlFile, newJavadocsRuntimeXmlContent);
      }
    }
  }
예제 #12
0
  private void _process(String command, String limit, Boolean ignoreAutogenerated)
      throws Exception {

    DirectoryScanner ds = new DirectoryScanner();

    ds.setBasedir(_basedir);
    ds.setExcludes(new String[] {"**\\classes\\**", "**\\portal-client\\**", "**\\portal-web\\**"});

    List<String> includes = new ArrayList<String>();

    if (Validator.isNotNull(limit) && !limit.startsWith("$")) {
      String[] limitArray = StringUtil.split(limit, '/');

      for (String curLimit : limitArray) {
        includes.add("**\\" + StringUtil.replace(curLimit, ".", "\\") + "\\**\\*.java");
        includes.add("**\\" + curLimit + ".java");
      }
    } else {
      includes.add("**\\*.java");
    }

    ds.setIncludes(includes.toArray(new String[includes.size()]));

    ds.scan();

    String[] fileNames = ds.getIncludedFiles();

    for (String fileName : fileNames) {
      fileName = StringUtil.replace(fileName, "\\", "/");

      /*if (!fileName.endsWith("Isolation.java")) {
      	continue;
      }*/

      if ((ignoreAutogenerated != null) && (ignoreAutogenerated.booleanValue())) {

        File file = new File(_basedir + fileName);

        if (file.exists()) {
          String oldContent = _fileUtil.read(_basedir + fileName + "doc");

          if (_isGenerated(oldContent)) {
            continue;
          }
        }
      }

      if (command.equals("cleanup")) {
        _processGet(fileName);
        _processSave(fileName);
        _processDelete(fileName);
      } else if (command.equals("commit")) {
        _processSave(fileName);
        _processDelete(fileName);
      } else if (command.equals("delete")) {
        _processDelete(fileName);
      } else if (command.equals("get")) {
        _processGet(fileName);
      } else if (command.equals("save")) {
        _processSave(fileName);
      }
    }
  }