Java Code Examples for org.codehaus.plexus.util.FileUtils#fileExists()

The following examples show how to use org.codehaus.plexus.util.FileUtils#fileExists() . 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: AbstractLangProcessor.java    From depends with MIT License 6 votes vote down vote up
private List<String> buildIncludePath() {
	includePaths = new ArrayList<String>();
	for (String path : includeDirs) {
		if (FileUtils.fileExists(path)) {
			path = FileUtil.uniqFilePath(path);
			if (!includePaths.contains(path))
				includePaths.add(path);
		}
		path = this.inputSrcPath + File.separator + path;
		if (FileUtils.fileExists(path)) {
			path = FileUtil.uniqFilePath(path);
			if (!includePaths.contains(path))
				includePaths.add(path);
		}
	}
	return includePaths;
}
 
Example 2
Source File: AjcHelper.java    From aspectj-maven-plugin with MIT License 6 votes vote down vote up
/**
 * Based on a set of weavedirs returns a set of all the files to be weaved.
 *
 * @return
 * @throws MojoExecutionException
 */
public static Set<String> getWeaveSourceFiles( String[] weaveDirs )
    throws MojoExecutionException
{
    Set<String> result = new HashSet<String>();

    for ( int i = 0; i < weaveDirs.length; i++ )
    {
        String weaveDir = weaveDirs[i];
        if ( FileUtils.fileExists( weaveDir ) )
        {
            try
            {
                result.addAll( FileUtils.getFileNames( new File( weaveDir ), "**/*.class", DEFAULT_EXCLUDES, true ) );
            }
            catch ( IOException e )
            {
                throw new MojoExecutionException( "IO Error resolving weavedirs", e );
            }
        }
    }
    return result;
}
 
Example 3
Source File: AjcHelper.java    From aspectj-maven-plugin with MIT License 6 votes vote down vote up
/**
 * Reads a build config file, and returns the List of all compiler arguments.
 *
 * @param fileName the filename of the argfile
 * @param outputDir the build output area
 * @return
 * @throws IOException
 */
public static List<String> readBuildConfigFile( String fileName, File outputDir )
    throws IOException
{
    List<String> arguments = new ArrayList<String>();
    File argFile = new File( outputDir, fileName );
    if ( FileUtils.fileExists( argFile.getAbsolutePath() ) )
    {
        FileReader reader = new FileReader( argFile );
        BufferedReader bufRead = new BufferedReader( reader );
        String line = null;
        do
        {
            line = bufRead.readLine();
            if ( null != line )
            {
                arguments.add( line );
            }
        }
        while ( null != line );
    }
    return arguments;
}
 
Example 4
Source File: BuildFrontendMojoTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@After
public void teardown() throws IOException {
    if (FileUtils.fileExists(packageJson)) {
        FileUtils.fileDelete(packageJson);
    }
    if (FileUtils.fileExists(webpackConfig)) {
        FileUtils.fileDelete(webpackConfig);
    }
}
 
Example 5
Source File: BuildFrontendMojoTest.java    From flow with Apache License 2.0 5 votes vote down vote up
static JsonObject getPackageJson(String packageJson) throws IOException {
    if (FileUtils.fileExists(packageJson)) {
        return Json.parse(FileUtils.fileRead(packageJson));

    } else {
        return Json.createObject();
    }
}
 
Example 6
Source File: AjcHelper.java    From aspectj-maven-plugin with MIT License 5 votes vote down vote up
/**
 * Based on a set of sourcedirs, apply include and exclude statements and
 * returns a set of all the files to be compiled and weaved.
 *
 * @param sourceDirs
 * @param includes
 * @param excludes
 * @return
 * @throws MojoExecutionException
 */
public static Set<String> getBuildFilesForSourceDirs( List<String> sourceDirs, String[] includes, String[] excludes )
    throws MojoExecutionException
{
    Set<String> result = new LinkedHashSet<String>();

    for ( String sourceDir : sourceDirs )
    {
        try
        {
            if ( FileUtils.fileExists( sourceDir ) )
            {
                result.addAll( FileUtils
                    .getFileNames( new File( sourceDir ),
                                   ( null == includes || 0 == includes.length ) ? DEFAULT_INCLUDES
                                                                               : getAsCsv( includes ),
                                   ( null == excludes || 0 == excludes.length ) ? DEFAULT_EXCLUDES
                                                                               : getAsCsv( excludes ), true ) );
            }
        }
        catch ( IOException e )
        {
            throw new MojoExecutionException( "IO Error resolving sourcedirs", e );
        }
    }
    // We might need to check if some of these files are already included through the weaveDirectories.

    return result;
}
 
Example 7
Source File: AjcHelper.java    From aspectj-maven-plugin with MIT License 5 votes vote down vote up
/**
 * Helper method to find all .java or .aj files specified by the
 * includeString. The includeString is a comma separated list over files, or
 * directories relative to the specified basedir. Examples of correct
 * listings
 *
 * <pre>
 *         src/main/java/
 *         src/main/java
 *         src/main/java/com/project/AClass.java
 *         src/main/java/com/project/AnAspect.aj
 *         src/main/java/com/project/AnAspect.java
 * </pre>
 *
 * @param input
 * @param basedir the baseDirectory
 * @return a list over all files inn the include string
 * @throws IOException
 */
protected static Set<String> resolveIncludeExcludeString( String input, File basedir )
    throws MojoExecutionException
{
    Set<String> inclExlSet = new LinkedHashSet<String>();
    try
    {
        if ( null == input || input.trim().equals( "" ) )
        {
            return inclExlSet;
        }
        String[] elements = input.split( "," );
        if ( null != elements )
        {

            for ( int i = 0; i < elements.length; i++ )
            {
                String element = elements[i];
                if ( element.endsWith( ".java" ) || element.endsWith( ".aj" ) )
                {
                    inclExlSet.addAll( FileUtils.getFileNames( basedir, element, "", true ) );
                }
                else
                {
                    File lookupBaseDir = new File( basedir, element );
                    if ( FileUtils.fileExists( lookupBaseDir.getAbsolutePath() ) )
                    {
                        inclExlSet.addAll( FileUtils.getFileNames( lookupBaseDir, DEFAULT_INCLUDES, "",
                                                               true ) );
                    }
                }
            }
        }
    }
    catch ( IOException e )
    {
        throw new MojoExecutionException( "Could not resolve java or aspect sources to compile", e );
    }
    return inclExlSet;
}
 
Example 8
Source File: AjcHelperTest.java    From aspectj-maven-plugin with MIT License 5 votes vote down vote up
/**
 * 
 * @throws Exception
 */
public void testBuildConfigFile()
{
    final File baseDir = new File(".");
    final String fileName = "test.lst";
    final String fileAbsolutePath = baseDir.getAbsolutePath() + File.separator + fileName;
    
    List args = new ArrayList();
    args.add("-classpath");
    args.add("a:b:c");
    args.add("-showWeaveInfo");
    args.add("/home/aspectj/AFile");
    args.add("/home/aspectj/AnotherFile");
    try
    {
        AjcHelper.writeBuildConfigToFile(args,fileName,baseDir);
        assertTrue("Config file not written to disk",FileUtils.fileExists(fileAbsolutePath));
        List readArgs = AjcHelper.readBuildConfigFile(fileName,baseDir);
        assertEquals(args,readArgs);
    } catch (Exception e)
    {
        fail("Unexpected exception: " + e.toString());
        if (FileUtils.fileExists(fileAbsolutePath))
        {
            FileUtils.fileDelete(fileAbsolutePath);
        }
    }
}
 
Example 9
Source File: GenerateMojo.java    From celerio with Apache License 2.0 5 votes vote down vote up
private Metadata getMetaData(String xmlMetaData) throws XmlMappingException, IOException, ClassNotFoundException, SQLException {
    if (isNotBlank(xmlMetaData)) {
        return getMetadataFromFile(xmlMetaData);
    } else if (FileUtils.fileExists(DEFAULT_XML_METADATA)) {
        return getMetadataFromFile(DEFAULT_XML_METADATA);
    } else {
        return getMetadataFromDatabase();
    }
}
 
Example 10
Source File: GenerateMojo.java    From celerio with Apache License 2.0 5 votes vote down vote up
private Celerio getCelerio(String xmlConfiguration) {
    Celerio celerio;

    if (FileUtils.fileExists(xmlConfiguration)) {
        celerio = getCelerioConfigurationFromFile(xmlConfiguration);
    } else {
        getLog().warn("****** The Celerio configuration file [" + xmlConfiguration + "] could not be found. Will use default empty configuration ******");
        celerio = new Celerio();
    }

    overridePacksAndModules(celerio);
    return celerio;
}
 
Example 11
Source File: GenerateMojo.java    From celerio with Apache License 2.0 5 votes vote down vote up
/**
 * For convenience (multi module, springfuse, etc...) template packs and modules may be in a separate file... we process this file if it exists.
 *
 * @param celerio
 */
private void overridePacksAndModules(Celerio celerio) {
    String filename = xmlTemplatePacksOverride;
    if (!FileUtils.fileExists(filename)) {
        return;
    }
    getLog().info("Overriding configuration with " + filename);

    CelerioLoader celerioLoader = context.getBean(CelerioLoader.class);
    try {
        Configuration configuration = celerioLoader.load(filename).getConfiguration();
        // override celerioContext
        CelerioTemplateContext ctc = configuration.getCelerioTemplateContext();
        if (ctc != null) {
            celerio.getConfiguration().setCelerioTemplateContext(ctc);
        }

        // override packs
        List<Pack> newPacks = configuration.getPacks();
        if (newPacks != null && !newPacks.isEmpty()) {
            celerio.getConfiguration().setPacks(newPacks);
        }

        // override modules
        List<Module> newModules = configuration.getModules();
        if (newModules != null && !newModules.isEmpty()) {
            celerio.getConfiguration().setModules(newModules);
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not do override: ["+ filename + "]", e);
    }
}
 
Example 12
Source File: Utils.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if there is at least one resource folder inside the project.
 *
 * @param project
 * @return
 */
public static boolean hasResourceFolders( MavenProject project ){
    List<Resource> resources = project.getResources();
    for ( Resource res : resources ){
        if ( FileUtils.fileExists( res.getDirectory() ) ){
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: Utils.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * @param projectPath
 * @return
 * @throws MojoExecutionException
 */
public static String getGitConfigFolder( String projectPath ) throws MojoExecutionException {
    projectPath = forceNoSlashOnDir( projectPath );

    while ( !FileUtils.fileExists( projectPath + File.separator + ".git" ) ) {
        int lastSlashIndex = projectPath.lastIndexOf( File.separator );
        if ( lastSlashIndex < 1 ) {
            throw new MojoExecutionException( "There are no local git repository associated with this project" );
        }
        projectPath = projectPath.substring( 0, lastSlashIndex );
    }
    return projectPath + File.separator + ".git";
}