org.apache.maven.shared.model.fileset.FileSet Java Examples

The following examples show how to use org.apache.maven.shared.model.fileset.FileSet. 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: AggregationTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrderOfFileSet() {
    FileSet fs = new FileSet();
    fs.setDirectory("target/test-classes/aggregation");
    fs.setIncludes(
            ImmutableList.of(
                    "core/the-first-to-aggregate.js",
                    "core/**/*.js",
                    "utils/**/*.js",
                    "plugins/**/*uses*.js",
                    "plugins/**/*.js"
            )
    );
    Aggregation aggregation = new Aggregation();
    aggregation.setFileSets(ImmutableList.of(fs));

    final Collection<File> included = aggregation.getSelectedFiles(new File("target"));
    assertThat(included).hasSize(5);
    // Check order
    assertThat(Iterables.get(included, 0).getAbsolutePath()).isEqualToIgnoringCase(
            new File("target/test-classes/aggregation/core/the-first-to-aggregate.js").getAbsolutePath());
    assertThat(Iterables.get(included, 1).getAbsolutePath()).isEqualToIgnoringCase(
            new File("target/test-classes/aggregation/core/a.js").getAbsolutePath());
    assertThat(Iterables.get(included, 4).getAbsolutePath()).isEqualToIgnoringCase(
            new File("target/test-classes/aggregation/plugins/another-file.js").getAbsolutePath());
}
 
Example #2
Source File: AggregationTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void testExcludes() {
    FileSet fs = new FileSet();
    fs.setDirectory("target/test-classes/aggregation");
    fs.setIncludes(
            ImmutableList.of(
                    "core/the-first-to-aggregate.js",
                    "core/**/*.js",
                    "utils/**/*.js",
                    "plugins/**/*uses*.js",
                    "plugins/**/*.js"
            )
    );
    fs.setExcludes(
            ImmutableList.of("**/another-file*")
    );
    Aggregation aggregation = new Aggregation();
    aggregation.setFileSets(ImmutableList.of(fs));

    final Collection<File> included = aggregation.getSelectedFiles(new File("target"));
    assertThat(included).hasSize(4);
    assertThat(Iterables.get(included, 0).getAbsolutePath()).isEqualToIgnoringCase(
            new File("target/test-classes/aggregation/core/the-first-to-aggregate.js").getAbsolutePath());
    assertThat(Iterables.get(included, 1).getAbsolutePath()).isEqualToIgnoringCase(
            new File("target/test-classes/aggregation/core/a.js").getAbsolutePath());
}
 
Example #3
Source File: WebJarPackagerTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void testIncludesCustomization() throws MojoExecutionException, IOException {
    WebJarPackager packager = new WebJarPackager();
    packager.project = mock(MavenProject.class);
    packager.projectHelper = mock(MavenProjectHelper.class);
    when(packager.project.getArtifactId()).thenReturn("test");
    when(packager.project.getVersion()).thenReturn("1.0");
    when(packager.project.getBasedir()).thenReturn(fake);
    packager.buildDirectory = new File("target/junk");
    copy();
    packager.webjar = new WebJar();
    FileSet set = new FileSet();
    set.setDirectory(new File(classes, "assets").getAbsolutePath());
    set.setIncludes(ImmutableList.of("**/coffee/*"));
    packager.webjar.setFileset(set);

    packager.execute();
    final File wj = new File(packager.buildDirectory, "test-1.0-webjar.jar");
    assertThat(wj).isFile();
    JarFile jar = new JarFile(wj);
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/missing")).isNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/coffee/script.coffee")).isNotNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/less/style.less")).isNull();
}
 
Example #4
Source File: WebJarPackagerTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void testExcludesCustomization() throws MojoExecutionException, IOException {
    WebJarPackager packager = new WebJarPackager();
    packager.project = mock(MavenProject.class);
    packager.projectHelper = mock(MavenProjectHelper.class);
    when(packager.project.getArtifactId()).thenReturn("test");
    when(packager.project.getVersion()).thenReturn("1.0");
    when(packager.project.getBasedir()).thenReturn(fake);
    packager.buildDirectory = new File("target/junk");
    copy();
    packager.webjar = new WebJar();
    FileSet set = new FileSet();
    set.setDirectory(new File(classes, "assets").getAbsolutePath());
    set.setExcludes(ImmutableList.of("**/less/*"));
    packager.webjar.setFileset(set);

    packager.execute();
    final File wj = new File(packager.buildDirectory, "test-1.0-webjar.jar");
    assertThat(wj).isFile();
    JarFile jar = new JarFile(wj);
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/missing")).isNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/coffee/script.coffee")).isNotNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/less/style.less")).isNull();
}
 
Example #5
Source File: Aggregation.java    From wisdom with Apache License 2.0 5 votes vote down vote up
private DirectoryScanner newScanner(File base, FileSet fileSet) {
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(base);
    if ((fileSet.getExcludes() != null) && (fileSet.getExcludes().size() != 0)) {
        scanner.setExcludes(fileSet.getExcludesArray());
    }
    scanner.addDefaultExcludes();
    return scanner;
}
 
Example #6
Source File: WebJar.java    From wisdom with Apache License 2.0 5 votes vote down vote up
/**
 * @return the selected set of files.
 */
public Collection<File> getSelectedFiles() {
    // Because of a symlink issue on OpenJDK, we cannot use the FileSetManager directory, because we need to
    // override a method from the DirectoryScanner.
    // The exception is: java.lang.ClassNotFoundException: sun/nio/fs/AixFileSystemProvider

    final FileSet set = getFileset();
    String[] names = FILESET_MANAGER.getIncludedFiles(set);
    List<File> files = new ArrayList<>();
    File base = new File(set.getDirectory());
    for (String n : names) {
        files.add(new File(base, n));
    }
    return files;
}
 
Example #7
Source File: AggregationTest.java    From wisdom with Apache License 2.0 5 votes vote down vote up
@Test
public void testOrderOfFileSets() {
    FileSet fs1 = new FileSet();
    fs1.setDirectory("target/test-classes/aggregation");
    fs1.setIncludes(
            ImmutableList.of(
                    "core/the-first-to-aggregate.js",
                    "core/**/*.js",
                    "utils/**/*.js",
                    "plugins/**/*uses*.js",
                    "plugins/**/*.js"
            )
    );

    FileSet fs2 = new FileSet();
    fs2.setDirectory("target/test-classes/aggregation");
    fs2.setIncludes(
            ImmutableList.of(
                    "utils/**/*.js",
                    "plugins/**/*uses*.js",
                    "plugins/**/*.js"
            )
    );

    Aggregation aggregation = new Aggregation();
    aggregation.setFileSets(ImmutableList.of(fs1, fs2));

    final Collection<File> included = aggregation.getSelectedFiles(new File("target"));
    assertThat(included).hasSize(5);
    // Check order
    assertThat(Iterables.get(included, 0).getAbsolutePath()).isEqualToIgnoringCase(
            new File("target/test-classes/aggregation/core/the-first-to-aggregate.js").getAbsolutePath());
    assertThat(Iterables.get(included, 1).getAbsolutePath()).isEqualToIgnoringCase(
            new File("target/test-classes/aggregation/core/a.js").getAbsolutePath());
    assertThat(Iterables.get(included, 4).getAbsolutePath()).isEqualToIgnoringCase(
            new File("target/test-classes/aggregation/plugins/another-file.js").getAbsolutePath());
}
 
Example #8
Source File: AbstractUpToDatePropertyMojo.java    From build-helper-maven-plugin with MIT License 4 votes vote down vote up
private File getFile( FileSet fileSet, boolean useOutputDirectory, String path )
{
    String baseDir = useOutputDirectory && !StringUtils.isBlank( fileSet.getOutputDirectory() )
                    ? fileSet.getOutputDirectory() : fileSet.getDirectory();
    return path == null ? null : new File( baseDir, path );
}
 
Example #9
Source File: UpToDatePropertySetting.java    From build-helper-maven-plugin with MIT License 4 votes vote down vote up
public FileSet getFileSet()
{
    return fileSet;
}
 
Example #10
Source File: UpToDatePropertySetting.java    From build-helper-maven-plugin with MIT License 4 votes vote down vote up
public void setFileSet( FileSet fileSet )
{
    this.fileSet = fileSet;
}
 
Example #11
Source File: Aggregation.java    From wisdom with Apache License 2.0 4 votes vote down vote up
/**
 * @return the file sets.
 */
public List<FileSet> getFileSets() {
    return fileSets;
}
 
Example #12
Source File: WebJar.java    From wisdom with Apache License 2.0 4 votes vote down vote up
/**
 * @return the file set.
 */
public FileSet getFileset() {
    return fileset;
}
 
Example #13
Source File: WebJarPackager.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@Override
public void execute() throws MojoExecutionException {
    if (!enabled()) {
        removeFromWatching();
        return;
    }

    FileSet set = new FileSet();
    set.setDirectory(getInternalAssetOutputDirectory().getAbsolutePath());
    if (webjar == null) {
        webjar = new WebJar(project.getArtifactId(), project.getVersion(), "webjar", set);
    } else {
        if (webjar.getFileset() == null) {
            webjar.setFileset(set);
        } else if (webjar.getFileset().getDirectory() == null) {
            getLog().info("No directory define in the webjar fileset - use the AssetOutputDirectory");
            webjar.getFileset().setDirectory(getInternalAssetOutputDirectory().getAbsolutePath());
        }

        if (webjar.getName() == null) {
            webjar.setName(project.getArtifactId());
        }
        if (webjar.getVersion() == null) {
            webjar.setVersion(project.getVersion());
        }
        if (webjar.getClassifier() == null) {
            webjar.setClassifier("webjar");
        }
    }

    try {
        File out = process();
        if (out != null) {
            projectHelper.attachArtifact(project, out, webjar.getClassifier());
            if (deployWebJarToWisdom) {
                copyToDestination(out);
            }
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Failure while building the webjar", e);
    }
}
 
Example #14
Source File: WebJar.java    From wisdom with Apache License 2.0 3 votes vote down vote up
/**
 * Creates an instance of {@link org.wisdom.maven.mojos.WebJar}.
 *
 * @param name       the name
 * @param version    the version
 * @param classifier the classifier
 * @param fileset    the file set
 */
public WebJar(String name, String version, String classifier, FileSet fileset) {
    this();
    setName(name);
    setVersion(version);
    setClassifier(classifier);
    setFileset(fileset);
}
 
Example #15
Source File: Aggregation.java    From wisdom with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the file sets to include in the aggregation.
 *
 * @param fileSets the file sets
 */
public void setFileSets(List<FileSet> fileSets) {
    this.fileSets = fileSets;
}
 
Example #16
Source File: WebJar.java    From wisdom with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the file set to include in the webjar.
 *
 * @param fileset the file set
 */
public void setFileset(FileSet fileset) {
    this.fileset = fileset;
}