Search in sources :

Example 1 with Source

use of org.apache.felix.scrplugin.Source in project felix by apache.

the class SCRDescriptorBndPlugin method getClassFiles.

private Collection<Source> getClassFiles(Analyzer analyzer) throws Exception {
    ArrayList<Source> files = new ArrayList<Source>();
    Collection<Clazz> expanded = analyzer.getClasses("", QUERY.NAMED.toString(), "*");
    for (final Clazz c : expanded) {
        files.add(new Source() {

            public File getFile() {
                log.debug("Found class " + c.getAbsolutePath());
                return new File(c.getAbsolutePath());
            }

            public String getClassName() {
                return c.getFQN();
            }
        });
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) Clazz(aQute.bnd.osgi.Clazz) File(java.io.File) Source(org.apache.felix.scrplugin.Source)

Example 2 with Source

use of org.apache.felix.scrplugin.Source in project felix by apache.

the class MavenProjectScanner method getSourcesForScanKind.

private Collection<Source> getSourcesForScanKind(ScanKind scanKind) throws AssertionError {
    final ArrayList<Source> files = new ArrayList<Source>();
    @SuppressWarnings("unchecked") final Iterator<String> i = project.getCompileSourceRoots().iterator();
    // FELIX-509: check for excludes
    String[] includes = new String[] { "**/*.java" };
    if (includeString != null) {
        includes = includeString.split(",");
    }
    final String[] excludes;
    if (excludeString != null) {
        excludes = excludeString.split(",");
    } else {
        excludes = null;
    }
    while (i.hasNext()) {
        final String tree = i.next();
        final File directory = new File(tree);
        if (!directory.exists()) {
            log.warn("Source tree does not exist. Ignoring " + tree);
            continue;
        }
        log.debug("Scanning source tree " + tree);
        final Scanner scanner;
        switch(scanKind) {
            case ADDED_OR_UPDATED:
                scanner = this.buildContext.newScanner(directory, false);
                break;
            case DELETED:
                scanner = this.buildContext.newDeleteScanner(directory);
                break;
            default:
                throw new AssertionError("Unhandled ScanKind " + scanKind);
        }
        if (excludes != null && excludes.length > 0) {
            scanner.setExcludes(excludes);
        }
        scanner.addDefaultExcludes();
        scanner.setIncludes(includes);
        scanner.scan();
        for (final String fileName : scanner.getIncludedFiles()) {
            files.add(new Source() {

                public File getFile() {
                    return new File(directory, fileName);
                }

                public String getClassName() {
                    // remove ".java"
                    String name = fileName.substring(0, fileName.length() - 5);
                    return name.replace(File.separatorChar, '/').replace('/', '.');
                }
            });
        }
    }
    return files;
}
Also used : Scanner(org.codehaus.plexus.util.Scanner) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) ArrayList(java.util.ArrayList) File(java.io.File) Source(org.apache.felix.scrplugin.Source)

Example 3 with Source

use of org.apache.felix.scrplugin.Source in project felix by apache.

the class MavenProjectScanner method getSources.

/**
 * Return all sources.
 */
public Collection<Source> getSources() {
    if (scanClasses) {
        final ArrayList<Source> files = new ArrayList<Source>();
        final DirectoryScanner scanner = new DirectoryScanner();
        scanner.setBasedir(this.project.getBuild().getOutputDirectory());
        if (this.includeString != null) {
            scanner.setIncludes(this.includeString.split(","));
        } else {
            scanner.setIncludes(new String[] { "**/*.class" });
        }
        if (this.excludeString != null) {
            scanner.setExcludes(this.excludeString.split(","));
        }
        scanner.addDefaultExcludes();
        scanner.scan();
        for (final String fileName : scanner.getIncludedFiles()) {
            files.add(new Source() {

                public File getFile() {
                    return new File(project.getBuild().getOutputDirectory(), fileName);
                }

                public String getClassName() {
                    // remove ".class"
                    String name = fileName.substring(0, fileName.length() - 6);
                    return name.replace(File.separatorChar, '/').replace('/', '.');
                }
            });
        }
        return files;
    }
    return getSourcesForScanKind(ScanKind.ADDED_OR_UPDATED);
}
Also used : DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) ArrayList(java.util.ArrayList) File(java.io.File) Source(org.apache.felix.scrplugin.Source)

Example 4 with Source

use of org.apache.felix.scrplugin.Source in project felix by apache.

the class SCRDescriptorMojo method deleteOutputFilesForSources.

private void deleteOutputFilesForSources(final Collection<Source> sources, final Options options) {
    final File componentDir = options.getComponentDescriptorDirectory();
    final File mtDir = options.getMetaTypeDirectory();
    for (final Source source : sources) {
        final File metaTypeFile = new File(mtDir, source.getClassName() + ".xml");
        getLog().debug("Deleting " + metaTypeFile + " ");
        boolean deleted = metaTypeFile.delete();
        if (deleted) {
            buildContext.refresh(metaTypeFile);
        }
        final File metaTypePropsFile = new File(mtDir, source.getClassName() + ".properties");
        getLog().debug("Deleting " + metaTypePropsFile + " ");
        deleted = metaTypePropsFile.delete();
        if (deleted) {
            buildContext.refresh(metaTypePropsFile);
        }
        final File componentDescriptorFile = new File(componentDir, source.getClassName() + ".xml");
        getLog().debug("Deleting " + componentDescriptorFile);
        deleted = componentDescriptorFile.delete();
        if (deleted) {
            buildContext.refresh(componentDescriptorFile);
        }
    }
}
Also used : File(java.io.File) Source(org.apache.felix.scrplugin.Source)

Example 5 with Source

use of org.apache.felix.scrplugin.Source in project felix by apache.

the class SCRDescriptorTask method getSourceFiles.

protected Collection<Source> getSourceFiles(final FileSet sourceFiles) {
    final String prefix = sourceFiles.getDir().getAbsolutePath();
    final int prefixLength = prefix.length() + 1;
    final List<Source> result = new ArrayList<Source>();
    @SuppressWarnings("unchecked") final Iterator<Resource> resources = sourceFiles.iterator();
    final String ext;
    if (scanClasses) {
        ext = ".class";
    } else {
        ext = ".java";
    }
    while (resources.hasNext()) {
        final Resource r = resources.next();
        if (r instanceof FileResource) {
            final File file = ((FileResource) r).getFile();
            if (file.getName().endsWith(ext)) {
                result.add(new Source() {

                    public File getFile() {
                        return file;
                    }

                    public String getClassName() {
                        String name = file.getAbsolutePath().substring(prefixLength).replace(File.separatorChar, '/').replace('/', '.');
                        return name.substring(0, name.length() - ext.length());
                    }
                });
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Resource(org.apache.tools.ant.types.Resource) FileResource(org.apache.tools.ant.types.resources.FileResource) FileResource(org.apache.tools.ant.types.resources.FileResource) File(java.io.File) Source(org.apache.felix.scrplugin.Source)

Aggregations

Source (org.apache.felix.scrplugin.Source)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 DirectoryScanner (org.codehaus.plexus.util.DirectoryScanner)2 Clazz (aQute.bnd.osgi.Clazz)1 SCRDescriptorException (org.apache.felix.scrplugin.SCRDescriptorException)1 SCRDescriptorFailureException (org.apache.felix.scrplugin.SCRDescriptorFailureException)1 ClassDescription (org.apache.felix.scrplugin.description.ClassDescription)1 Resource (org.apache.tools.ant.types.Resource)1 FileResource (org.apache.tools.ant.types.resources.FileResource)1 Scanner (org.codehaus.plexus.util.Scanner)1