+ project.getVersion() );
}
Set<Artifact> artifactDependencies = new HashSet<Artifact>();
ValueFactory valueFactory = rdfRepository.getValueFactory();
URI id =
valueFactory.createURI( project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion()
+ ":" + project.getArtifactType() );
URI groupId = valueFactory.createURI( ProjectUri.GROUP_ID.getPredicate() );
URI artifactId = valueFactory.createURI( ProjectUri.ARTIFACT_ID.getPredicate() );
URI version = valueFactory.createURI( ProjectUri.VERSION.getPredicate() );
URI artifactType = valueFactory.createURI( ProjectUri.ARTIFACT_TYPE.getPredicate() );
URI classifier = valueFactory.createURI( ProjectUri.CLASSIFIER.getPredicate() );
URI isResolved = valueFactory.createURI( ProjectUri.IS_RESOLVED.getPredicate() );
URI artifact = valueFactory.createURI( ProjectUri.ARTIFACT.getPredicate() );
URI dependency = valueFactory.createURI( ProjectUri.DEPENDENCY.getPredicate() );
URI parent = valueFactory.createURI( ProjectUri.PARENT.getPredicate() );
Set<Model> modelDependencies = new HashSet<Model>();
try
{
repositoryConnection.add( id, RDF.TYPE, artifact );
repositoryConnection.add( id, groupId, valueFactory.createLiteral( project.getGroupId() ) );
repositoryConnection.add( id, artifactId, valueFactory.createLiteral( project.getArtifactId() ) );
repositoryConnection.add( id, version, valueFactory.createLiteral( project.getVersion() ) );
repositoryConnection.add( id, artifactType, valueFactory.createLiteral( project.getArtifactType() ) );
if ( project.getPublicKeyTokenId() != null )
{
URI classifierNode = valueFactory.createURI( project.getPublicKeyTokenId() + ":" );
for ( Requirement requirement : project.getRequirements() )
{
URI uri = valueFactory.createURI( requirement.getUri().toString() );
repositoryConnection.add( classifierNode, uri, valueFactory.createLiteral( requirement.getValue() ) );
}
repositoryConnection.add( id, classifier, classifierNode );
}
if ( project.getParentProject() != null )
{
Project parentProject = project.getParentProject();
URI pid =
valueFactory.createURI( parentProject.getGroupId() + ":" + parentProject.getArtifactId() + ":"
+ parentProject.getVersion() + ":" + project.getArtifactType() );
repositoryConnection.add( id, parent, pid );
artifactDependencies.addAll( storeProjectAndResolveDependencies( parentProject, null,
artifactRepositories, cache ) );
}
for ( ProjectDependency projectDependency : project.getProjectDependencies() )
{
Artifact assembly = createArtifactFrom( projectDependency, artifactFactory );
snapshotVersion = null;
if(!assembly.getFile().exists())
{
try
{
ArtifactRepository localArtifactRepository =
new DefaultArtifactRepository( "local", "file://" + localRepository,
new DefaultRepositoryLayout() );
artifactResolver.resolve( assembly, artifactRepositories,
localArtifactRepository );
}
catch ( ArtifactNotFoundException e )
{
logger.warning( "NPANDAY-181-121: Problem in resolving assembly: " + assembly.toString()
+ ", Message = " + e.getMessage() );
}
catch ( ArtifactResolutionException e )
{
logger.warning( "NPANDAY-181-122: Problem in resolving assembly: " + assembly.toString()
+ ", Message = " + e.getMessage() );
}
}
logger.finer( "NPANDAY-180-011: Project Dependency: Artifact ID = "
+ projectDependency.getArtifactId() + ", Group ID = " + projectDependency.getGroupId()
+ ", Version = " + projectDependency.getVersion() + ", Artifact Type = "
+ projectDependency.getArtifactType() );
// If artifact has been deleted, then re-resolve
if ( projectDependency.isResolved() && !ArtifactTypeHelper.isDotnetAnyGac( projectDependency.getArtifactType() ) )
{
if ( projectDependency.getSystemPath() == null )
{
projectDependency.setSystemPath( generateDependencySystemPath( projectDependency ) );
}
File dependencyFile = PathUtil.getDotNetArtifact( assembly , localRepository );
if ( !dependencyFile.exists() )
{
projectDependency.setResolved( false );
}
}
// resolve system scope dependencies
if ( projectDependency.getScope() != null && projectDependency.getScope().equals( "system" ) )
{
if ( projectDependency.getSystemPath() == null )
{
throw new ProjectDaoException( "systemPath required for System Scoped dependencies " + "in Group ID = "
+ projectDependency.getGroupId() + ", Artiract ID = " + projectDependency.getArtifactId() );
}
File f = new File( projectDependency.getSystemPath() );
if ( !f.exists() )
{
throw new IOException( "Dependency systemPath File not found:"
+ projectDependency.getSystemPath() + "in Group ID = " + projectDependency.getGroupId()
+ ", Artiract ID = " + projectDependency.getArtifactId() );
}
assembly.setFile( f );
assembly.setResolved( true );
artifactDependencies.add( assembly );
projectDependency.setResolved( true );
logger.finer( "NPANDAY-180-011.1: Project Dependency Resolved: Artifact ID = "
+ projectDependency.getArtifactId() + ", Group ID = " + projectDependency.getGroupId()
+ ", Version = " + projectDependency.getVersion() + ", Scope = " + projectDependency.getScope()
+ "SystemPath = " + projectDependency.getSystemPath()
);
continue;
}
// resolve com reference
// flow:
// 1. generate the interop dll in temp folder and resolve to that path during dependency resolution
// 2. cut and paste the dll to buildDirectory and update the paths once we grab the reference of
// MavenProject (CompilerContext.java)
if ( projectDependency.getArtifactType().equals( "com_reference" ) )
{
String tokenId = projectDependency.getPublicKeyTokenId();
String interopPath = generateInteropDll( projectDependency.getArtifactId(), tokenId );
File f = new File( interopPath );
if ( !f.exists() )
{
throw new IOException( "Dependency com_reference File not found:" + interopPath
+ "in Group ID = " + projectDependency.getGroupId() + ", Artiract ID = "
+ projectDependency.getArtifactId() );
}
assembly.setFile( f );
assembly.setResolved( true );
artifactDependencies.add( assembly );
projectDependency.setResolved( true );
logger.fine( "NPANDAY-180-011.1: Project Dependency Resolved: Artifact ID = "
+ projectDependency.getArtifactId() + ", Group ID = " + projectDependency.getGroupId()
+ ", Version = " + projectDependency.getVersion() + ", Scope = " + projectDependency.getScope()
+ "SystemPath = " + projectDependency.getSystemPath()
);
continue;
}
// resolve gac references
// note: the old behavior of gac references, used to have system path properties in the pom of the
// project
// now we need to generate the system path of the gac references so we can use
// System.getenv("SystemRoot")
//we have already set file for the assembly above (in createArtifactFrom) so we do not need re-resovle it
if ( !projectDependency.isResolved() )
{
if ( ArtifactTypeHelper.isDotnetAnyGac( projectDependency.getArtifactType() ) )
{
try
{
if (assembly.getFile().exists())
{
projectDependency.setSystemPath( assembly.getFile().getAbsolutePath());
projectDependency.setResolved( true );
assembly.setResolved( true );
}
artifactDependencies.add( assembly );
}
catch ( ExceptionInInitializerError e )
{
logger.warning( "NPANDAY-180-516.82: Project Failed to Resolve Dependency: Artifact ID = "
+ projectDependency.getArtifactId() + ", Group ID = " + projectDependency.getGroupId()
+ ", Version = " + projectDependency.getVersion() + ", Scope = "
+ projectDependency.getScope() + "SystemPath = " + projectDependency.getSystemPath() );
}
}
else
{
try
{
// re-resolve snapshots
if ( !assembly.isSnapshot() )
{
Project dep =
this.getProjectFor( projectDependency.getGroupId(), projectDependency.getArtifactId(),
projectDependency.getVersion(),
projectDependency.getArtifactType(),
projectDependency.getPublicKeyTokenId() );
if ( dep.isResolved() )
{
projectDependency = (ProjectDependency) dep;
artifactDependencies.add( assembly );
Set<Artifact> deps = this.storeProjectAndResolveDependencies( projectDependency,
localRepository,
artifactRepositories,
cache );
artifactDependencies.addAll( deps );
}
}
}
catch ( ProjectDaoException e )
{
logger.log( Level.WARNING, e.getMessage() );
// safe to ignore: dependency not found
}
}
}
if ( !projectDependency.isResolved() )
{
logger.finest("NPANDAY-180-055: dependency:" + projectDependency.getClass());
logger.finest("NPANDAY-180-056: dependency:" + assembly.getClass());
if ( assembly.getType().equals( "jar" ) )
{
logger.info( "Detected jar dependency - skipping: Artifact Dependency ID = "
+ assembly.getArtifactId() );
continue;
}
ArtifactType type = ArtifactType.getArtifactTypeForPackagingName( assembly.getType() );
logger.finer( "NPANDAY-180-012: Resolving artifact for unresolved dependency: "
+ assembly.getId());
ArtifactRepository localArtifactRepository =
new DefaultArtifactRepository( "local", "file://" + localRepository,
new DefaultRepositoryLayout() );
if ( !ArtifactTypeHelper.isDotnetExecutableConfig( type ))// TODO: Generalize to any attached artifact
{
logger.finest( "NPANDAY-180-016: set file....");
Artifact pomArtifact =
artifactFactory.createProjectArtifact( projectDependency.getGroupId(),
projectDependency.getArtifactId(),
projectDependency.getVersion() );
try
{
artifactResolver.resolve( pomArtifact, artifactRepositories,
localArtifactRepository );
projectDependency.setResolved( true );
logger.finer( "NPANDAY-180-024: resolving pom artifact: " + pomArtifact.toString() );
snapshotVersion = pomArtifact.getVersion();
}
catch ( ArtifactNotFoundException e )
{
logger.warning( "NPANDAY-180-025: Problem in resolving pom artifact: " + pomArtifact.toString()
+ ", Message = " + e.getMessage() );
}
catch ( ArtifactResolutionException e )
{
logger.warning( "NPANDAY-180-026: Problem in resolving pom artifact: " + pomArtifact.toString()
+ ", Message = " + e.getMessage() );
}
if ( pomArtifact.getFile() != null && pomArtifact.getFile().exists() )
{
FileReader fileReader = new FileReader( pomArtifact.getFile() );
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model;
try
{
model = reader.read( fileReader ); // TODO: interpolate values
}
catch ( XmlPullParserException e )
{
throw new IOException( "NPANDAY-180-015: Unable to read model: Message = "
+ e.getMessage() + ", Path = " + pomArtifact.getFile().getAbsolutePath() );
}
catch ( EOFException e )
{
throw new IOException( "NPANDAY-180-016: Unable to read model: Message = "
+ e.getMessage() + ", Path = " + pomArtifact.getFile().getAbsolutePath() );
}
// small hack for not doing inheritence
String g = model.getGroupId();
if ( g == null )
{
g = model.getParent().getGroupId();
}
String v = model.getVersion();
if ( v == null )
{
v = model.getParent().getVersion();
}
if ( !( g.equals( projectDependency.getGroupId() )
&& model.getArtifactId().equals( projectDependency.getArtifactId() ) && v.equals( projectDependency.getVersion() ) ) )
{
throw new ProjectDaoException(
"NPANDAY-180-017: Model parameters do not match project dependencies parameters: Model: "
+ g + ":" + model.getArtifactId() + ":" + v + ", Project: "
+ projectDependency.getGroupId() + ":"
+ projectDependency.getArtifactId() + ":"
+ projectDependency.getVersion() );
}
if( model.getArtifactId().equals( projectDependency.getArtifactId() ) && projectDependency.isResolved() )
{
modelDependencies.add( model );
}
}
}
logger.finest( "NPANDAY-180-019: set file...");
if ( snapshotVersion != null )
{
assembly.setVersion( snapshotVersion );
}
File dotnetFile = PathUtil.getDotNetArtifact( assembly , localRepository );
logger.warning( "NPANDAY-180-018: Not found in local repository, now retrieving artifact from wagon:"
+ assembly.getId()
+ ", Failed Path Check = " + dotnetFile.getAbsolutePath());
if ( !ArtifactTypeHelper.isDotnetExecutableConfig( type ) || !dotnetFile.exists() )// TODO: Generalize to any attached artifact
{
try
{
artifactResolver.resolve( assembly, artifactRepositories,
localArtifactRepository );
projectDependency.setResolved( true );
if ( assembly != null && assembly.getFile().exists() )
{
dotnetFile.getParentFile().mkdirs();
FileUtils.copyFile( assembly.getFile(), dotnetFile );
assembly.setFile( dotnetFile );
}
}
catch ( ArtifactNotFoundException e )
{
logger.log(Level.SEVERE, "NPANDAY-180-0201: Error resolving artifact. Reason:", e);
throw new ProjectDaoException(
"NPANDAY-180-020: Problem in resolving artifact: Artifact = "
+ assembly.getId()
+ ", Message = " + e.getMessage(), e );
}
catch ( ArtifactResolutionException e )
{
logger.log( Level.SEVERE, "NPANDAY-180-019: Problem in resolving artifact: Artifact = "
+ assembly.getId()
+ ", Message = " + e.getMessage(), e );
throw new ProjectDaoException(
"NPANDAY-180-019: Problem in resolving artifact: Artifact = "
+ assembly.getId()
+ ", Message = " + e.getMessage(), e );
}
}
artifactDependencies.add( assembly );
}// end if dependency not resolved
URI did =
valueFactory.createURI( projectDependency.getGroupId() + ":" + projectDependency.getArtifactId()
+ ":" + projectDependency.getVersion() + ":" + projectDependency.getArtifactType() );
repositoryConnection.add( did, RDF.TYPE, artifact );
repositoryConnection.add( did, groupId, valueFactory.createLiteral( projectDependency.getGroupId() ) );
repositoryConnection.add( did, artifactId,
valueFactory.createLiteral( projectDependency.getArtifactId() ) );
repositoryConnection.add( did, version, valueFactory.createLiteral( projectDependency.getVersion() ) );
repositoryConnection.add( did, artifactType,
valueFactory.createLiteral( projectDependency.getArtifactType() ) );
if ( projectDependency.getPublicKeyTokenId() != null )
{
repositoryConnection.add(
did,
classifier,
valueFactory.createLiteral( projectDependency.getPublicKeyTokenId() + ":" ) );
}
repositoryConnection.add( id, dependency, did );
}// end for
repositoryConnection.add( id, isResolved, valueFactory.createLiteral( true ) );
repositoryConnection.commit();
}
catch ( OpenRDFException e )
{
if ( repositoryConnection != null )