Example #1
0
  public String[] getIncludedDirectories(FileSet fileSet) {
    DirectoryScanner scanner = scan(fileSet);

    if (scanner != null) {
      return scanner.getIncludedDirectories();
    }

    return EMPTY_STRING_ARRAY;
  }
Example #2
0
  public void produce(final DataConsumer pReceiver) throws IOException {
    String user = "******";
    int uid = 0;
    String group = "root";
    int gid = 0;
    int filemode = TarEntry.DEFAULT_FILE_MODE;
    int dirmode = TarEntry.DEFAULT_DIR_MODE;
    String prefix = "";

    if (fileset instanceof Tar.TarFileSet) {
      Tar.TarFileSet tarfileset = (Tar.TarFileSet) fileset;
      user = tarfileset.getUserName();
      uid = tarfileset.getUid();
      group = tarfileset.getGroup();
      gid = tarfileset.getGid();
      filemode = tarfileset.getMode();
      dirmode = tarfileset.getDirMode(tarfileset.getProject());
      prefix = tarfileset.getPrefix(tarfileset.getProject());
    }

    final DirectoryScanner scanner = fileset.getDirectoryScanner(fileset.getProject());
    scanner.scan();

    final File basedir = scanner.getBasedir();

    final String[] directories = scanner.getIncludedDirectories();
    for (int i = 0; i < directories.length; i++) {
      final String name = directories[i].replace('\\', '/');

      pReceiver.onEachDir(prefix + "/" + name, null, user, uid, group, gid, dirmode, 0);
    }

    final String[] files = scanner.getIncludedFiles();
    for (int i = 0; i < files.length; i++) {
      final String name = files[i].replace('\\', '/');
      final File file = new File(basedir, name);

      final InputStream inputStream = new FileInputStream(file);
      try {
        pReceiver.onEachFile(
            inputStream, prefix + "/" + name, null, user, uid, group, gid, filemode, file.length());
      } finally {
        inputStream.close();
      }
    }
  }
Example #3
0
 /**
  * Fulfill the ResourceCollection contract.
  *
  * @return an Iterator of Resources.
  */
 public synchronized Iterator iterator() {
   if (isReference()) {
     return getRef().iterator();
   }
   ensureDirectoryScannerSetup();
   ds.scan();
   int fct = ds.getIncludedFilesCount();
   int dct = ds.getIncludedDirsCount();
   if (fct + dct == 0) {
     return EMPTY_ITERATOR;
   }
   FileResourceIterator result = new FileResourceIterator(getProject());
   if (fct > 0) {
     result.addFiles(ds.getIncludedFiles());
   }
   if (dct > 0) {
     result.addFiles(ds.getIncludedDirectories());
   }
   return result;
 }
Example #4
0
  private File manageFileSet(FileSet fs) throws IOException, InterruptedException {
    final DirectoryScanner ds = fs.getDirectoryScanner(getProject());
    final File fromDir = fs.getDir(getProject());

    final String[] srcFiles = ds.getIncludedFiles();
    final String[] srcDirs = ds.getIncludedDirectories();

    for (String src : srcFiles) {
      final File f = new File(fromDir, src);
      final boolean error = processingSingleFile(f);
      if (error) {
        return f;
      }
    }

    for (String src : srcDirs) {
      final File dir = new File(fromDir, src);
      final File errorFile = processingSingleDirectory(dir);
      if (errorFile != null) {
        return errorFile;
      }
    }
    return null;
  }
Example #5
0
  /**
   * Add the directories matched by the nested dirsets to the resulting packages list and the base
   * directories of the dirsets to the Path. It also handles the packages and excludepackages
   * attributes and elements.
   *
   * @param resultantPackages a list to which we add the packages found
   * @param sourcePath a path to which we add each basedir found
   * @since 1.5
   */
  private void parsePackages(List<String> resultantPackages, Path sourcePath) {
    List<String> addedPackages = new ArrayList<String>();
    List<DirSet> dirSets = new ArrayList<DirSet>(packageSets);

    // for each sourcePath entry, add a directoryset with includes
    // taken from packagenames attribute and nested package
    // elements and excludes taken from excludepackages attribute
    // and nested excludepackage elements
    if (this.sourcePath != null) {
      PatternSet ps = new PatternSet();
      if (packageNames.size() > 0) {
        for (String pn : packageNames) {
          String pkg = pn.replace('.', '/');
          if (pkg.endsWith("*")) {
            pkg += "*";
          }
          ps.createInclude().setName(pkg);
        }
      } else {
        ps.createInclude().setName("**");
      }

      for (String epn : excludePackageNames) {
        String pkg = epn.replace('.', '/');
        if (pkg.endsWith("*")) {
          pkg += "*";
        }
        ps.createExclude().setName(pkg);
      }

      String[] pathElements = this.sourcePath.list();
      for (String pathElement : pathElements) {
        File dir = new File(pathElement);
        if (dir.isDirectory()) {
          DirSet ds = new DirSet();
          ds.setDefaultexcludes(useDefaultExcludes);
          ds.setDir(dir);
          ds.createPatternSet().addConfiguredPatternset(ps);
          dirSets.add(ds);
        } else {
          log.warn("Skipping " + pathElement + " since it is no directory.");
        }
      }
    }

    for (DirSet ds : dirSets) {
      File baseDir = ds.getDir(getProject());
      log.debug("scanning " + baseDir + " for packages.");
      DirectoryScanner dsc = ds.getDirectoryScanner(getProject());
      String[] dirs = dsc.getIncludedDirectories();
      boolean containsPackages = false;
      for (String dir : dirs) {
        // are there any groovy or java files in this directory?
        File pd = new File(baseDir, dir);
        String[] files =
            pd.list(
                new FilenameFilter() {
                  public boolean accept(File dir1, String name) {
                    if (!includeNoSourcePackages && name.equals("package.html")) return true;
                    final StringTokenizer tokenizer = new StringTokenizer(extensions, ":");
                    while (tokenizer.hasMoreTokens()) {
                      String ext = tokenizer.nextToken();
                      if (name.endsWith(ext)) return true;
                    }
                    return false;
                  }
                });

        for (String filename : Arrays.asList(files)) {
          sourceFilesToDoc.add(dir + File.separator + filename);
        }

        if (files.length > 0) {
          if ("".equals(dir)) {
            log.warn(
                baseDir
                    + " contains source files in the default package,"
                    + " you must specify them as source files not packages.");
          } else {
            containsPackages = true;
            String pn = dir.replace(File.separatorChar, '.');
            if (!addedPackages.contains(pn)) {
              addedPackages.add(pn);
              resultantPackages.add(pn);
            }
          }
        }
      }
      if (containsPackages) {
        // We don't need to care for duplicates here,
        // Path.list does it for us.
        sourcePath.createPathElement().setLocation(baseDir);
      } else {
        log.verbose(baseDir + " doesn't contain any packages, dropping it.");
      }
    }
  }
Example #6
0
 /**
  * Return the list of Directories from this DirectoryScanner that should be included on the
  * command line - i.e. only those that are newer than the corresponding target files.
  */
 protected String[] getDirs(File baseDir, DirectoryScanner ds) {
   SourceFileScanner sfs = new SourceFileScanner(this);
   return sfs.restrict(ds.getIncludedDirectories(), baseDir, destDir, mapper);
 }
Example #7
0
  public void produce(final DataConsumer pReceiver) throws IOException {
    String user = Producers.ROOT_NAME;
    int uid = Producers.ROOT_UID;
    String group = Producers.ROOT_NAME;
    int gid = Producers.ROOT_UID;
    int filemode = TarEntry.DEFAULT_FILE_MODE;
    int dirmode = TarEntry.DEFAULT_DIR_MODE;
    String prefix = "";

    if (fileset instanceof Tar.TarFileSet) {
      Tar.TarFileSet tarfileset = (Tar.TarFileSet) fileset;
      user = tarfileset.getUserName();
      uid = tarfileset.getUid();
      group = tarfileset.getGroup();
      gid = tarfileset.getGid();
      filemode = tarfileset.getMode();
      dirmode = tarfileset.getDirMode(tarfileset.getProject());
      prefix = tarfileset.getPrefix(tarfileset.getProject());
    }

    final DirectoryScanner scanner = fileset.getDirectoryScanner(fileset.getProject());
    scanner.scan();

    final File basedir = scanner.getBasedir();

    for (String directory : scanner.getIncludedDirectories()) {
      String name = directory.replace('\\', '/');

      final TarArchiveEntry entry = new TarArchiveEntry(prefix + "/" + name);
      entry.setUserName(user);
      entry.setUserId(uid);
      entry.setGroupName(group);
      entry.setGroupId(gid);
      entry.setMode(dirmode);

      pReceiver.onEachDir(entry);
    }

    for (String filename : scanner.getIncludedFiles()) {
      final String name = filename.replace('\\', '/');
      final File file = new File(basedir, name);

      final InputStream inputStream = new FileInputStream(file);
      try {
        final String entryName = prefix + "/" + name;

        final File entryPath = new File(entryName);

        final boolean symbolicLink = SymlinkUtils.isSymbolicLink(entryPath);
        final TarArchiveEntry e;
        if (symbolicLink) {
          e = new TarArchiveEntry(entryName, TarConstants.LF_SYMLINK);
          e.setLinkName(SymlinkUtils.readSymbolicLink(entryPath));
        } else {
          e = new TarArchiveEntry(entryName, true);
        }

        e.setUserId(uid);
        e.setGroupId(gid);
        e.setUserName(user);
        e.setGroupName(group);
        e.setMode(filemode);
        e.setSize(file.length());

        pReceiver.onEachFile(inputStream, e);
      } finally {
        inputStream.close();
      }
    }
  }