本文整理汇总了Java中org.codehaus.plexus.util.Scanner类的典型用法代码示例。如果您正苦于以下问题:Java Scanner类的具体用法?Java Scanner怎么用?Java Scanner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Scanner类属于org.codehaus.plexus.util包,在下文中一共展示了Scanner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scan
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
/**
* Scans using the given plexus scanner.
* This is like {@link Sources#scan} but uses a provided scanner like one of
* the special purpose ones provided by
* {@link org.sonatype.plexus.build.incremental.BuildContext}.
*/
public ImmutableList<Source> scan(
Scanner s, Iterable<SourceFileProperty> ps)
throws IOException {
s.setIncludes(includes.toArray(EMPTY_STRING_ARRAY));
s.setExcludes(excludes.toArray(EMPTY_STRING_ARRAY));
s.scan();
String[] files = s.getIncludedFiles();
if (files == null) { return ImmutableList.of(); }
TypedFile root = new TypedFile(s.getBasedir().getCanonicalFile(), ps);
String prefix = root.f.getPath();
if (prefix.isEmpty()) { prefix = "."; }
if (!prefix.endsWith(File.separator)) {
prefix += File.separator;
}
ImmutableList.Builder<Source> sources = ImmutableList.builder();
for (String file : files) {
sources.add(new Source(
new File(prefix + file).getCanonicalFile(), root, new File(file)));
}
return sources.build();
}
示例2: getIncludedSources
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
protected Set<String> getIncludedSources()
throws MojoExecutionException {
Set<String> result = new HashSet<String>();
if (getJavaSources() == null) {
result = AjcHelper.getBuildFilesForSourceDirs(getSourceDirectories(), this.includes, this.excludes);
} else {
for (int scannerIndex = 0; scannerIndex < getJavaSources().length; scannerIndex++) {
Scanner scanner = getJavaSources()[scannerIndex];
if (scanner.getBasedir() == null) {
getLog().info("Source without basedir, skipping it.");
} else {
scanner.scan();
for (int fileIndex = 0; fileIndex < scanner.getIncludedFiles().length; fileIndex++) {
result.add(FileUtils.resolveFile(scanner.getBasedir(),
scanner.getIncludedFiles()[fileIndex]).getAbsolutePath());
}
}
}
}
return result;
}
示例3: getClasses
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
private List<Class> getClasses(final String sourceRoot, final String[] includes, final Predicate<Class> predicate)
throws Exception {
final Scanner scanner = buildContext.newScanner(new File(sourceRoot));
scanner.setIncludes(includes);
scanner.scan();
String[] sources = scanner.getIncludedFiles();
if (sources.length == 0) {
return new ArrayList<>();
}
List<Class> result = new ArrayList<>();
for (String source : sources) {
String className = AnalyzeHelper.getTopLevelClassName(source);
Class clazz = Class.forName(className, false, classLoader);
if (predicate.apply(clazz)) {
result.add(clazz);
}
}
return result;
}
示例4: isRebuildRequired
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
private boolean isRebuildRequired() {
if (ctx.isIncremental()) {
if ((grammarFile != null && ctx.hasDelta(grammarFile))
|| ctx.hasDelta(templateFile)
|| (inputFile != null && inputFile.isFile() && ctx.hasDelta(inputFile))) {
return true;
} else if (inputFile != null && inputFile.isDirectory()) {
Scanner scanner = ctx.newScanner(inputFile, true);
info("Scanning...");
scanner.scan();
if (scanner.getIncludedFiles() != null) {
for (String includedFile : scanner.getIncludedFiles()) {
if (ctx.hasDelta(new File(scanner.getBasedir(), includedFile))) {
info("Changes detected. Rebuilding.");
return true;
}
}
}
}
info("Nothing has changed.");
return false;
} else {
info("Full rebuild requested.");
return true;
}
}
示例5: shouldExecute
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
static boolean shouldExecute(BuildContext buildContext, List<File> triggerfiles, File srcdir) {
// If there is no buildContext, or this is not an incremental build, always execute.
if (buildContext == null || !buildContext.isIncremental()) {
return true;
}
if (triggerfiles != null) {
for (File triggerfile : triggerfiles) {
if (buildContext.hasDelta(triggerfile)) {
return true;
}
}
}
if (srcdir == null) {
return true;
}
// Check for changes in the srcdir
Scanner scanner = buildContext.newScanner(srcdir);
scanner.scan();
String[] includedFiles = scanner.getIncludedFiles();
return (includedFiles != null && includedFiles.length > 0);
}
示例6: execute
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
@Override
public void execute()
throws MojoExecutionException, MojoFailureException
{
mavenProject.addCompileSourceRoot( outputDirectory.getAbsolutePath() );
Scanner scanner = buildContext.newScanner( schemaDirectory );
scanner.scan();
if ( scanner.getIncludedFiles().length < 1 )
{
return;
}
if ( handleNativeDependency )
{
doHandleNativesDependency();
}
nativesManager.registerAllDescriptors();
workDirectory.mkdirs();
NativesInfo currentNativesInfo = nativesManager.getNativesInfoForCurrentPlatform();
CapnpCompiler compiler =
CapnpCompiler.builder()
.setOutputDirectory( outputDirectory )
.setSchemaDirectory( schemaDirectory )
.setWorkDirectory( workDirectory )
.setCapnpFile( copyResource( currentNativesInfo.getCapnpUrl(), workDirectory ) )
.setCapnpcJavaFile( copyResource( currentNativesInfo.getCapnpcJavaUrl(), workDirectory ) )
.setCapnpJavaSchemaFile( copyResource( currentNativesInfo.getCapnpJavaSchemaUrl(), workDirectory ) )
.addSchemas( getSchemas() )
.addImportDirectories( getImportDirectories() )
.setVerbose( verbose )
.build();
compiler.compile();
}
示例7: scanAndGeneratePages
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
private void scanAndGeneratePages(File sourceRoot) throws Exception
{
if (getLog().isDebugEnabled())
{
getLog().debug("Scanning source folder: "+sourceRoot.getCanonicalPath());
}
Scanner scanner = getScanner(sourceRoot);
scanner.setIncludes(new String[] { "**/*.crux.xml" });
scanner.scan();
String[] sources = scanner.getIncludedFiles();
if (sources.length == 0)
{
return;
}
for (String source : sources)
{
File sourceFile = new File(sourceRoot, source);
String viewId = getViewId(source);
if (!StringUtils.isEmpty(viewId))
{
File targetFile = getTargetFile(viewId);
if (isUptodate(targetFile, sourceFile))
{
getLog().debug(targetFile.getAbsolutePath() + " is up to date. Generation skipped");
continue;
}
getLog().info("Generating HTML page for file " + source);
targetFile.getParentFile().mkdirs();
generateHTMLPage(viewId, sourceFile, targetFile);
}
}
}
示例8: execute
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
/**
* Performs the conversion.
*
* @throws MojoExecutionException
* thrown when there is a problem executing Mjo.
*/
@Override
public void execute() throws MojoExecutionException {
destDir.mkdirs();
if (fontFileSets == null) {
final FileSet defaultFontFileSet = new FileSet();
defaultFontFileSet.setDirectory(new File(project.getBasedir(), "src/main/ttf").getPath());
defaultFontFileSet.addInclude("**/*.ttf");
fontFileSets = Collections.singletonList(defaultFontFileSet);
}
for (final FileSet fileSet : fontFileSets) {
final String directory = fileSet.getDirectory();
final File baseDirectory = new File(directory); // NOPMD
if (!baseDirectory.isDirectory()) { // NOPMD
getLog().warn(format(R.getString("missingdir"), directory));
continue;
}
final Scanner scanner = buildContext.newScanner(baseDirectory);
scanner.setIncludes(fileSet.getIncludes().toArray(new String[0])); // NOPMD
scanner.setExcludes(fileSet.getExcludes().toArray(new String[0])); // NOPMD
scanner.scan();
for (final String includedFile : scanner.getIncludedFiles()) {
final File inputFile = new File(baseDirectory, // NOPMD
includedFile);
final String basename = includedFile.substring(0, includedFile.lastIndexOf('.'));
final File svgFile = new File(destDir, basename + ".svg"); // NOPMD
try {
final PrintStream ps = new PrintStream(// NOPMD
buildContext.newFileOutputStream(svgFile));
SvgFontUtil.writeFontAsSvg(ps, Font.create(inputFile.toString()), basename);
ps.close();
} catch (final Exception e) {
throw new MojoExecutionException(String.format(R.getString("failedtorender"), inputFile), e);
}
}
}
}
示例9: compile
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
protected void compile() throws IOException {
File sourceDirectory = getSourcesDirectory();
File outputDirectory = getOutputDirectory();
if (!outputDirectory.exists()) {
outputDirectory.mkdirs();
}
Scanner fileScanner = context.newScanner(sourceDirectory, true);
fileScanner.setIncludes(includes);
fileScanner.setExcludes(excludes);
fileScanner.scan();
File basedir = fileScanner.getBasedir();
List<File> changedFiles = new ArrayList<File>();
for (String fileName : fileScanner.getIncludedFiles()) {
File file = new File(basedir, fileName);
changedFiles.add(file);
context.removeMessages(file);
}
if (!changedFiles.isEmpty()) {
try {
File[] schemaFile = changedFiles.toArray(new File[changedFiles.size()]);
GoraCompiler.compileSchema(schemaFile, outputDirectory);
} catch (SchemaParseException e) {
if (e.getCause() != null && e.getCause() instanceof JsonParseException) {
attachErrorMessage((JsonParseException) e.getCause());
} else {
throw e;
}
}
}
context.refresh(outputDirectory);
}
示例10: scanDirectoryForFiles
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
/**
* Scans given directory for files satisfying given inclusion/exclusion
* patterns.
*
* @param directory
* Directory to scan.
* @param includes
* inclusion pattern.
* @param excludes
* exclusion pattern.
* @param defaultExcludes
* default exclusion flag.
* @return Files from the given directory which satisfy given patterns. The
* files are {@link File#getCanonicalFile() canonical}.
*/
public static List<File> scanDirectoryForFiles(BuildContext buildContext,
final File directory, final String[] includes,
final String[] excludes, boolean defaultExcludes)
throws IOException {
if (!directory.exists()) {
return Collections.emptyList();
}
final Scanner scanner;
if (buildContext != null) {
scanner = buildContext.newScanner(directory, true);
} else {
final DirectoryScanner directoryScanner = new DirectoryScanner();
directoryScanner.setBasedir(directory.getAbsoluteFile());
scanner = directoryScanner;
}
scanner.setIncludes(includes);
scanner.setExcludes(excludes);
if (defaultExcludes) {
scanner.addDefaultExcludes();
}
scanner.scan();
final List<File> files = new ArrayList<File>();
for (final String name : scanner.getIncludedFiles()) {
files.add(new File(directory, name).getCanonicalFile());
}
return files;
}
示例11: compile
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
protected void compile() throws IOException {
File sourceDirectory = getSourcesDirectory();
File outputDirectory = getOutputDirectory();
if (!outputDirectory.exists()) {
outputDirectory.mkdirs();
}
Scanner fileScanner = context.newScanner(sourceDirectory, true);
fileScanner.setIncludes(includes);
fileScanner.setExcludes(excludes);
fileScanner.scan();
File basedir = fileScanner.getBasedir();
List<File> changedFiles = new ArrayList<File>();
for (String fileName : fileScanner.getIncludedFiles()) {
File file = new File(basedir, fileName);
changedFiles.add(file);
context.removeMessages(file);
}
if (!changedFiles.isEmpty()) {
try {
File[] schemaFile = changedFiles.toArray(new File[changedFiles.size()]);
GoraCompiler.compileSchema(schemaFile, outputDirectory);
} catch (SchemaParseException e) {
if (e.getCause() != null && e.getCause() instanceof JsonParseException) {
attachErrorMessage((JsonParseException) e.getCause());
} else {
throw e;
}
}
}
context.refresh(outputDirectory);
}
示例12: build
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
@Override
public Set<IProject> build( int kind, IProgressMonitor monitor )
throws Exception
{
IMaven maven = MavenPlugin.getMaven();
BuildContext buildContext = getBuildContext();
// check if any of the grammar files changed
File source = maven.getMojoParameterValue(getSession(), getMojoExecution(), "schemaDirectory", File.class);
Scanner ds = buildContext.newScanner( source ); // delta or full scanner
ds.scan();
String[] includedFiles = ds.getIncludedFiles();
if (includedFiles == null || includedFiles.length <= 0 )
{
return null;
}
// execute mojo
Set<IProject> result = super.build( kind, monitor );
// tell m2e builder to refresh generated files
File generated = maven.getMojoParameterValue(getSession(), getMojoExecution(), "dest", File.class);
if (generated != null) {
buildContext.refresh( generated );
}
return result;
}
示例13: findFiles
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
private List<File> findFiles(final Scanner scanner) {
final List<File> results = new ArrayList<File>();
if (includes != null && includes.length > 0) {
scanner.setIncludes(includes);
}
if (excludes != null && excludes.length > 0) {
scanner.setExcludes(excludes);
}
scanner.addDefaultExcludes();
scanner.scan();
for (final String name : scanner.getIncludedFiles()) {
results.add(new File(scanner.getBasedir(), name));
}
return results;
}
示例14: findFiles
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
private List<File> findFiles(final Scanner scanner) {
final List<File> results = new ArrayList<File>();
scanner.setIncludes(modulesArray);
scanner.scan();
for (final String name : scanner.getIncludedFiles()) {
results.add(new File(scanner.getBasedir(), name));
}
return results;
}
示例15: getSourceFiles
import org.codehaus.plexus.util.Scanner; //导入依赖的package包/类
private Set<File> getSourceFiles()
{
if (source == null || !source.exists())
{
return new TreeSet<>();
}
String[] filters = ALL_JAVA_FILES_FILTER;
if (includes != null && !includes.isEmpty())
{
filters = includes.toArray(new String[includes.size()]);
for (int i = 0; i < filters.length; i++)
{
filters[i] = filters[i].replace('.', '/') + JAVA_FILE_FILTER;
}
}
Set<File> files = new HashSet<File>();
final Scanner scanner = buildContext.newScanner(source);
scanner.setIncludes(filters);
scanner.scan();
String[] includedFiles = scanner.getIncludedFiles();
if (includedFiles != null)
{
for (String includedFile : includedFiles)
{
files.add(new File(scanner.getBasedir(), includedFile));
}
}
return files;
}