Java Code Examples for org.apache.tools.ant.types.FileSet#setProject()

The following examples show how to use org.apache.tools.ant.types.FileSet#setProject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileFinder.java    From warnings-ng-plugin with MIT License 6 votes vote down vote up
/**
 * Returns an array with the file names of the specified file pattern that have been found in the workspace.
 *
 * @param workspace
 *         root directory of the workspace
 *
 * @return the file names of all found files
 */
public String[] find(final File workspace) {
    try {
        FileSet fileSet = new FileSet();
        Project antProject = new Project();
        fileSet.setProject(antProject);
        fileSet.setDir(workspace);
        fileSet.setIncludes(includesPattern);
        TypeSelector selector = new TypeSelector();
        FileType fileType = new FileType();
        fileType.setValue(FileType.FILE);
        selector.setType(fileType);
        fileSet.addType(selector);
        if (StringUtils.isNotBlank(excludesPattern)) {
            fileSet.setExcludes(excludesPattern);
        }
        fileSet.setFollowSymlinks(followSymlinks);

        return fileSet.getDirectoryScanner(antProject).getIncludedFiles();
    }
    catch (BuildException ignored) {
        return new String[0]; // as fallback do not return any file
    }
}
 
Example 2
Source File: Zip.java    From Export with Apache License 2.0 6 votes vote down vote up
/**
 * ʹ��zipѹ���ļ�
 * 
 * @param source
 *            ��Ҫѹ�����ļ�
 * @param target
 *            ѹ�����ļ��Ĵ��·��
 * @param delflag
 *            ѹ�����Ƿ�ɾ��Դ�ļ�
 */
public static void compress(File source, File target, boolean delflag) {
	if (!target.exists()) {
		target.mkdirs();
	}
	File zipFile = new File(target.getAbsolutePath() + File.separator
			+ source.getName() + ".zip");
	Project prj = new Project();
	org.apache.tools.ant.taskdefs.Zip zip = new org.apache.tools.ant.taskdefs.Zip();
	zip.setProject(prj);
	zip.setDestFile(zipFile);
	FileSet fileSet = new FileSet();
	fileSet.setProject(prj);
	fileSet.setDir(target);
	// ������Щ�ļ����ļ���
	fileSet.setIncludes(source.getName());
	// �ų���Щ�ļ����ļ���
	fileSet.setExcludes("*.zip");
	zip.addFileset(fileSet);
	zip.execute();
	if (delflag) {
		source.delete();
	}
}
 
Example 3
Source File: AntBuildResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    TestHelper.cleanCache();
    project = TestHelper.newProject();
    project.setProperty("ivy.cache.dir", TestHelper.cache.getAbsolutePath());

    AntWorkspaceResolver antWorkspaceResolver = new AntWorkspaceResolver();
    antWorkspaceResolver.setName("test-workspace");
    wa = antWorkspaceResolver.createArtifact();
    FileSet fileset = new FileSet();
    fileset.setProject(project);
    fileset.setDir(new File("test/workspace"));
    fileset.setIncludes("*/ivy.xml");
    antWorkspaceResolver.addConfigured(fileset);
    antWorkspaceResolver.setProject(project);

    configure = new IvyConfigure();
    configure.setProject(project);
    configure.setFile(new File("test/workspace/ivysettings.xml"));
    configure.addConfiguredWorkspaceResolver(antWorkspaceResolver);
    configure.execute();
}
 
Example 4
Source File: JarExpander.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
private FileSet createFileSetForJarFile(File jarFile, Project prj)
{
    FileSet fileSet = new FileSet();
    fileSet.setProject(prj);
    fileSet.setFile(jarFile);
    return fileSet;
}
 
Example 5
Source File: ExclusionsFromLicenseInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void execute() throws BuildException {
    try (FileOutputStream fos = new FileOutputStream(new File(getProject().getBaseDir(), exclusionFile));
            OutputStreamWriter osw = new OutputStreamWriter(fos);
            BufferedWriter bw = new BufferedWriter(osw)) {
        Path nballPath = nball.toPath();
        List<File> licenseinfofiles = Files.walk(nballPath)
                .filter(p -> p.endsWith("licenseinfo.xml"))
                .map(p -> p.toFile())
                .collect(Collectors.toList());

        FileSet licenseinfoFileset = new FileSet();
        licenseinfoFileset.setProject(getProject());
        licenseinfoFileset.setDir(nball.getAbsoluteFile());

        for(File licenseInfoFile: licenseinfofiles) {
            Licenseinfo li = Licenseinfo.parse(licenseInfoFile);
            for(Fileset fs: li.getFilesets()) {
                for(File f: fs.getFiles()) {
                    Path relativePath = nball.toPath().relativize(f.toPath());
                    licenseinfoFileset.appendIncludes(new String[]{relativePath.toString()});
                    bw.write(relativePath.toString());
                    bw.newLine();
                }
            }
        }
        
        getProject().addReference(this.licenseinfoFileset, licenseinfoFileset);
    } catch (IOException ex) {
        throw new BuildException(ex);
    }
}
 
Example 6
Source File: MakeMasterJNLP.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public FileSet createModules()
throws BuildException {
    FileSet fs = new FileSet();
    fs.setProject(getProject());
    addConfigured(fs);
    return fs;
}
 
Example 7
Source File: MakeJNLP.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public FileSet createModules()
throws BuildException {
    FileSet fs = new FileSet();
    fs.setProject(getProject());
    addConfigured(fs);
    return fs;
}
 
Example 8
Source File: AntTask.java    From forbidden-apis with Apache License 2.0 5 votes vote down vote up
/** Sets a directory as base for class files. The implicit pattern '**&#47;*.class' is used to only scan class files. */
public void setDir(File dir) {
  final FileSet fs = new FileSet();
  fs.setProject(getProject());
  fs.setDir(dir);
  // needed if somebody sets restrictClassFilename=false:
  fs.setIncludes("**/*.class");
  classFiles.add(fs);
}
 
Example 9
Source File: BundleLocator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void processBundlePath()
{
  if (null!=bundlePath && 0<bundlePath.length()) {
    final URL baseUrl = getBaseURL();
    // Create a file set for each entry in the bundle path.
    final String[] urls = Util.splitwords(this.bundlePath, ";", '"');
    for (final String url2 : urls) {
      log("Processing URL '" + url2 + "' from bundlePath '"
          + this.bundlePath + "'.", Project.MSG_DEBUG);
      try {
        final URL url = new URL(baseUrl, url2.trim());
        if ("file".equals(url.getProtocol())) {
          final String path = url.getPath();
          final File dir = new File(path.replace('/', File.separatorChar));
          log("Adding file set with dir '" + dir
              + "' for bundlePath file URL with path '" + path + "'.",
              Project.MSG_VERBOSE);
          final FileSet fs = new FileSet();
          fs.setDir(dir);
          fs.setExcludes("**/*-source.jar,**/*-javadoc.jar");
          fs.setIncludes("**/*.jar");
          fs.setProject(getProject());
          filesets.add(fs);
        }
      } catch (final MalformedURLException e) {
        throw new BuildException("Invalid URL, '" + url2
                                 + "' found in bundlePath: '"
                                 + bundlePath + "'.", e);
      }
    }
  }
}
 
Example 10
Source File: IvyCacheFileset.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public void doExecute() throws BuildException {
    prepareAndCheck();
    if (setid == null) {
        throw new BuildException("setid is required in ivy cachefileset");
    }
    try {
        final List<ArtifactDownloadReport> artifactDownloadReports = getArtifactReports();
        if (artifactDownloadReports.isEmpty()) {
            // generate an empty fileset
            final FileSet emptyFileSet = new EmptyFileSet();
            emptyFileSet.setProject(getProject());
            getProject().addReference(setid, emptyFileSet);
            return;
        }
        // find a common base dir of the resolved artifacts
        final File baseDir = this.requireCommonBaseDir(artifactDownloadReports);
        final FileSet fileset = new FileSet();
        fileset.setDir(baseDir);
        fileset.setProject(getProject());
        // enroll each of the artifact files into the fileset
        for (final ArtifactDownloadReport artifactDownloadReport : artifactDownloadReports) {
            if (artifactDownloadReport.getLocalFile() == null) {
                continue;
            }
            final NameEntry ne = fileset.createInclude();
            ne.setName(getPath(baseDir, artifactDownloadReport.getLocalFile()));
        }
        getProject().addReference(setid, fileset);
    } catch (Exception ex) {
        throw new BuildException("impossible to build ivy cache fileset: " + ex, ex);
    }
}
 
Example 11
Source File: BundleClasspathTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void execute() throws BuildException {
  if (   (null==propertyName || 0==propertyName.length())
         && (null==filesetId    || 0==filesetId.length()) ) {
    throw new BuildException
      ("Either propertyName or filesetId must be given.");
  }
  if (null!=filesetId && dir==null) {
    throw new BuildException
      ("dir is required when filesetId is given.");
  }

  if (null==bundleClasspath || 0==bundleClasspath.length() ) {
    bundleClasspath = ".";
  }

  final StringBuffer sb = new StringBuffer(100);

  // Convert path entries to patterns.
  final StringTokenizer st = new StringTokenizer(bundleClasspath, ",");
  while (st.hasMoreTokens()) {
    String entry = st.nextToken().trim();
    if (entry.startsWith("/")) {
      // Entry is a relative path, must not start with a '/', fix it.
      entry = entry.substring(1);
    }

    if (".".equals(entry)) {
      sb.append("**/*.class");
    } else if (entry.endsWith(".jar")) {
      sb.append(entry);
    } else {
      sb.append(entry + "/**/*.class");
    }
    if (st.hasMoreTokens()) {
      sb.append(",");
    }
  }

  final Project proj = getProject();

  // Conversion done - write back properties
  if (null!=propertyName) {
    proj.setProperty(propertyName, sb.toString());
    log("Converted \"" +bundleClasspath +"\" to pattern \""
        +sb.toString() +"\"",
        Project.MSG_VERBOSE);
  }

  if (null!=filesetId) {
    final FileSet fileSet = new FileSet();
    fileSet.setProject(proj);
    if (dir.exists()) {
      fileSet.setDir(dir);
      fileSet.setIncludes(sb.toString());
    } else {
      log("Bundle class path root dir '" +dir
          +"' does not exist, returning empty file set.",
          Project.MSG_DEBUG);
      fileSet.setDir(new File("."));
      fileSet.setExcludes("**/*");
    }
    proj.addReference(filesetId, fileSet);
    log("Converted bundle class path \"" +bundleClasspath
        +"\" to file set with id '" +filesetId
        +"' and files \"" +fileSet +"\"",
        Project.MSG_VERBOSE);
  }
}