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, 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();
 }
 private String[] findJsonFiles(File targetDirectory) {
   DirectoryScanner scanner = new DirectoryScanner();
   scanner.setIncludes(new String[] {"**/*.json"});
   scanner.setBasedir(targetDirectory);
   scanner.scan();
   return scanner.getIncludedFiles();
 }
Ejemplo n.º 4
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);
     }
   }
 }
Ejemplo n.º 6
0
 private synchronized void ensureDirectoryScannerSetup() {
   dieOnCircularReference();
   if (ds == null) {
     ds = new DirectoryScanner();
     PatternSet ps = mergePatterns(getProject());
     ds.setIncludes(ps.getIncludePatterns(getProject()));
     ds.setExcludes(ps.getExcludePatterns(getProject()));
     ds.setSelectors(getSelectors(getProject()));
     if (useDefaultExcludes) {
       ds.addDefaultExcludes();
     }
     ds.setCaseSensitive(caseSensitive);
     ds.setFollowSymlinks(followSymlinks);
   }
 }
  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);
  }
Ejemplo n.º 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;
  }
  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));
    }
  }
Ejemplo n.º 10
0
  @Override
  public void execute() throws BuildException {
    ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
    try {
      // make sure RESTEasy classes will be found:
      Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
      DirectoryScanner ds = getDirectoryScanner(srcDir);
      // use default includes if unset:
      if (!getImplicitFileSet().hasPatterns()) {
        ds.setIncludes(new String[] {"**/*.properties"}); // $NON-NLS-1$
      }
      ds.setSelectors(getSelectors());
      ds.scan();
      String[] files = ds.getIncludedFiles();

      Marshaller m = null;
      // JAXBContext jc = JAXBContext.newInstance(Documents.class);
      // m = jc.createMarshaller();
      if (debug) {
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
      }

      // Documents docs = new Documents();
      // List<Document> docList = docs.getDocuments();
      PropReader propReader = new PropReader();
      // for each of the base props files under srcdir:
      int i = 0;
      for (String filename : files) {
        progress.update(i++, files.length);
        // Document doc = new Document(filename, ContentType.TextPlain);
        // doc.setLang(LocaleId.fromJavaName(sourceLang));
        File f = new File(srcDir, filename);
        // propReader.extractAll(doc, f, locales, contentState);
        // docList.add(doc);
      }
      progress.finished();
      if (debug) {
        StringWriter writer = new StringWriter();
        // m.marshal(docs, writer);
        log.debug("{}", writer);
      }

      if (dst == null) return;

      URL dstURL = Utility.createURL(dst, getProject());
      if ("file".equals(dstURL.getProtocol())) {
        // m.marshal(docs, new File(dstURL.getFile()));
      } else {
        // send project to rest api
        ZanataProxyFactory factory =
            new ZanataProxyFactory(user, apiKey, new VersionInfo("SNAPSHOT", "Unknow"));
        // IDocumentsResource documentsResource =
        // factory.getDocuments(dstURL.toURI());
        // ClientResponse response = documentsResource.put(docs);
        // ClientUtility.checkResult(response, dstURL.toURI());
      }

    } catch (Exception e) {
      throw new BuildException(e);
    } finally {
      Thread.currentThread().setContextClassLoader(oldLoader);
    }
  }
Ejemplo n.º 11
0
  @Override
  public void execute() throws BuildException {
    DirUtil.checkDir(dir1, "dir1", false); // $NON-NLS-1$
    DirUtil.checkDir(dir2, "dir2", false); // $NON-NLS-1$

    if (mapper == null) {
      add(new IdentityMapper());
    }
    try {
      DirectoryScanner ds = super.getDirectoryScanner(dir1);
      // use default includes if unset:
      if (!getImplicitFileSet().hasPatterns())
        ds.setIncludes(new String[] {"**/*.properties"}); // $NON-NLS-1$
      ds.scan();
      String[] files = ds.getIncludedFiles();

      for (int i = 0; i < files.length; i++) {
        String prop1Filename = files[i];
        File prop1File = new File(dir1, prop1Filename);
        String[] outFile = mapper.getImplementation().mapFileName(prop1Filename);
        if (outFile == null || outFile.length == 0) {
          if (failOnNull)
            throw new BuildException("Input filename " + prop1File + " mapped to null");
          log("Skipping " + prop1File + ": filename mapped to null", Project.MSG_VERBOSE);
          continue;
        }
        String prop2Filename = outFile[0]; // FIXME support multiple output mappings?
        File prop2File = new File(dir2, prop2Filename);

        Properties props1 = new Properties();
        InputStream in1 = new FileInputStream(prop1File);
        try {
          props1.load(in1);
          Properties props2 = new Properties();
          InputStream in2 = new FileInputStream(prop2File);
          try {
            props2.load(in2);
            int errorCount = 0;
            StringBuilder errors = new StringBuilder();
            errors.append(prop1File.getPath() + " is different from " + prop2File.getPath() + ": ");
            errors.append(System.getProperty("line.separator")); // $NON-NLS-1$

            for (Map.Entry<Object, Object> entry : props1.entrySet()) {
              String propName = (String) entry.getKey();
              String prop1Val = (String) entry.getValue();
              String prop2Val = (String) props2.remove(propName);
              if (!equivalent(prop1Val, prop2Val)) {
                ++errorCount;
                recordError(
                    errors,
                    propName + " -> {" + prop1Val + ", " + prop2Val
                        + "}"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
              }
            }
            if (!props2.isEmpty()) {
              ++errorCount;
              String message = "second file contains extra keys: " + props2.keySet();
              recordError(errors, message);
            }

            if (errorCount != 0) throw new BuildException(errors.toString());
          } finally {
            in2.close();
          }
        } finally {
          in1.close();
        }
      }
      log("Verified .properties files in " + dir1 + " against " + dir2, Project.MSG_VERBOSE);
    } catch (Exception e) {
      throw new BuildException(e);
    }
  }
Ejemplo n.º 12
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);
      }
    }
  }
Ejemplo n.º 13
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);
      }
    }
  }