URI enclosed = manager.getTargetURI( new URI( out.toURL().toString() ) );
URI enclosed = manager.getTargetURI( out.toURI() );
    private void checkType( Resource resource, Type type, boolean validate )    {        //        // Check that the project has actually built the resource        // type that it declares        //        String id = type.getID();        String filename = getContext().getLayoutFilename( id );        final File deliverables = getContext().getTargetDeliverablesDirectory();        File group = new File( deliverables, id + "s" );        File target = new File( group, filename );        if( !target.exists() && !id.equalsIgnoreCase( "null" ) )        {            final String error =               "Project ["               + resource               + "] declares that it produces the resource type ["              + id              + "] however no artifacts of that type are present in the target deliverables directory.";            throw new BuildException( error, getLocation() );        }        //        // If the type declares an alias then construct a link         // and add the link to the deliverables directory as part of         // install process.        //        Version version = type.getVersion();        if( null != version )        {            try            {                Artifact artifact = resource.getArtifact( id );                String uri = artifact.toURI().toASCIIString();                String link = null;                if( Version.NULL_VERSION.equals( version ) )                {                    link = resource.getName() + "." + id + ".link";                }                else                {                    link = resource.getName()                    + "-"                    + version.getMajor()                    + "."                     + version.getMinor()                    + "."                    + id + ".link";                }                File out = new File( group, link );                boolean flag = true;                if( out.exists() )                {                    ArtifactLinkManager manager = new ArtifactLinkManager();                    URI enclosed = manager.getTargetURI( new URI( out.toURL().toString() ) );                    if( artifact.toURI().equals( enclosed ) )                    {                        flag = false;                    }                }                                if( flag )                {                    final String message =                       link.toString()                      + "\n  target: "                       +  uri.toString();                    log( message, Project.MSG_VERBOSE );                    out.createNewFile();                    final OutputStream output = new FileOutputStream( out );                    final Writer writer = new OutputStreamWriter( output );                    writer.write( uri );                    writer.close();                    output.close();                }            }            catch( Exception e )            {                final String error =                   "Internal error while attempting to create a link for the resource type ["                  + id                   + "] in project ["                  + resource                  + "].";                throw new BuildException( error, e, getLocation() );            }        }        if( validate )        {            validateType( resource, type, target );        }    }