/*
 * #%L
 * Wisdom-Framework
 * %%
 * Copyright (C) 2013 - 2014 Wisdom Framework
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package org.wisdom.maven.mojos;


import org.apache.maven.shared.model.fileset.FileSet;
import org.apache.maven.shared.model.fileset.util.FileSetManager;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * The webjar configuration. Let you configure the file set included in the webjar, the classifier, the name and
 * version of the webjar.
 */
public class WebJar {

    FileSet fileset;

    String name;

    String version;

    String classifier;

    FileSetManager manager = new FileSetManager();

    /**
     * Creates an instance of {@link org.wisdom.maven.mojos.WebJar}.
     */
    public WebJar() {
        // Default constructor.
    }

    /**
     * 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);
    }

    /**
     * @return the file set.
     */
    public FileSet getFileset() {
        return fileset;
    }

    /**
     * Sets the file set to include in the webjar.
     *
     * @param fileset the file set
     */
    public void setFileset(FileSet fileset) {
        this.fileset = fileset;
    }

    /**
     * @return the name of the webjar.
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of the webjar.
     *
     * @param name the name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the version of the webjar.
     */
    public String getVersion() {
        return version;
    }

    /**
     * Sets the version of the webjar.
     *
     * @param version the version
     */
    public void setVersion(String version) {
        this.version = version;
    }

    /**
     * @return the artifact's classifier.
     */
    public String getClassifier() {
        return classifier;
    }

    /**
     * Sets the classifier.
     *
     * @param classifier the classifier
     */
    public void setClassifier(String classifier) {
        this.classifier = classifier;
    }

    /**
     * @return the artifact's file name.
     */
    public String getOutputFileName() {
        return getName() + "-" + getVersion() + "-" + getClassifier() + ".jar";
    }

    /**
     * @return the selected set of files.
     */
    public Collection<File> getSelectedFiles() {
        final FileSet set = getFileset();
        String[] names = 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;
    }

}

@@ -803,16 +803,66 @@
 Manager;
+%0Aimport org.codehaus.plexus.util.DirectoryScanner;
 %0A%0Aimport
@@ -3397,24 +3397,97 @@
 tFileset();%0A
+        // Disable symbolic links.%0A        set.setFollowSymlinks(false);%0A
         Stri
@@ -3739,11 +3739,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Disable symlink when looking for file to include in a web jar.