[forge-issues] [JBoss JIRA] (FORGE-430) Fix MavenCoreFacetImpl getPom()

Max Schwaab (JIRA) jira-events at lists.jboss.org
Tue Jan 17 07:42:18 EST 2012


    [ https://issues.jboss.org/browse/FORGE-430?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12659832#comment-12659832 ] 

Max Schwaab commented on FORGE-430:
-----------------------------------

Hi Lincoln,

maybe my explanation was a bit unsharp.

So I try to be more precise and give you the problem discription again.
If you think I should open another bug, I'll do that.

Task:

Install a plugin from a local project

Command:

forge source-plugin

The way to the MavenCoreFacet:

ForgePlugin.installFromLocalProject invokes
ForgePlugin.installFromCurrentProject invokes
ForgePlugin.createModule invokes
ForgePlugin.createDependenciesModule invokes
ForgePlugin.resolveArtifacts invokes
MavenDependencyFacet.getDependencies which finally invokes

{code}
MavenCoreFacet maven = project.getFacet(MavenCoreFacet.class);
Model pom = maven.getPOM();
{code}

The problem is, that ForgePlugin.resolveArtifacts compares the dependencies and sets the original dependency d to d2, which comes from the MavenCoreFacet with no resolved version (but the {some.version} property as version). 

So maybe the problem is in the ForgePlugin.resolveArtifacts method.
I pointed to the (possible) problem in the code.

{code}
   private List<DependencyResource> resolveArtifacts(final Project project, final Dependency dep) {
      Dependency d = dep;

      List<DependencyResource> artifacts = new ArrayList<DependencyResource>();
      DependencyFacet deps = project.getFacet(DependencyFacet.class);

      for (Dependency d2 : deps.getDependencies()) {
         if (DependencyBuilder.areEquivalent(d, d2) && (d2.getVersion() != null))
         {
            d = d2; //<- this results in a "Could not resolve dependency" message
            break;
         }
      }

      if (artifacts.size() != 1)
      {
         artifacts = resolver.resolveArtifacts(d, deps.getRepositories());
      }
      if (artifacts.size() != 1)
      {
         ShellMessages.warn(writer, "Could not resolve dependency [" + d.toCoordinates() + "]");
      }

      return artifacts;
}
{code}

Best regards

Max
                
> Fix MavenCoreFacetImpl getPom()
> -------------------------------
>
>                 Key: FORGE-430
>                 URL: https://issues.jboss.org/browse/FORGE-430
>             Project: Forge
>          Issue Type: Bug
>    Affects Versions: 1.0.0.Beta5
>         Environment: Windows 7, Desktop PC
>            Reporter: Max Schwaab
>            Assignee: Lincoln Baxter III
>            Priority: Minor
>              Labels: maven
>             Fix For: 1.0.0.CR1, Future
>
>
> Please have a look at org.jboss.forge.maven.facets.MavenCoreFacetImpl in the forge-project-model-maven project.
> The getPom() method reads the pom directly from the file resource. This results in a warning when using maven properties for dependency versions, e.g. when you try to install a plugin via the source-plugin command (***WARNING*** Could not resolve dependency [org.some:dependency:jar::${some.version}])
> The plugin works after installation and I don't know if its important to resolve this issue, but in the code is a "//FIXME"-remark too. The same may be relevant for setPOM(final Model pom) too.
> {code:title=MavenCoreFacetImpl getPom()}
>    @Override
>    public Model getPOM()
>    {
>       try
>       {
>          Model result = new Model();
>          // FIXME this should/can-not use the Maven Native file writer if we are going to abstract file APIs
>          MavenXpp3Reader reader = new MavenXpp3Reader();
>          FileInputStream stream = new FileInputStream(getPOMFile().getUnderlyingResourceObject());
>          if (stream.available() > 0)
>          {
>             result = reader.read(stream);
>          }
>          stream.close();
>          result.setPomFile(getPOMFile().getUnderlyingResourceObject());
>          return result;
>       }
>       catch (IOException e)
>       {
>          throw new ProjectModelException("Could not open POM file: " + getPOMFile(), e);
>       }
>       catch (XmlPullParserException e)
>       {
>          throw new ProjectModelException("Could not parse POM file: " + getPOMFile(), e);
>       }
>    }
> {code}
> Example for my plugins pom.xml
> {code}
> <project
> 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
> 	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> 	<properties>
> 		<some.version>1.0</some.version>
> 	</properties>
> 	<dependencies>
> 		<dependency>
> 			<groupId>org.some</groupId>
> 			<artifactId>dependency</artifactId>
> 			<version>${some.version}</version>
> 		</dependency>
> 	</dependencies>
> 	<repositories>
> 		<repository>
> 			<id>repository.some</id>
> 			<name>Some Repository for Maven</name>
> 			<url>http://some.repo.url</url>
> 		</repository>
> 	</repositories>
> </project>
> {code}
> Best regards
> Max

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the forge-issues mailing list