Commit 807db4df authored by Brian Long's avatar Brian Long
Browse files

better property fetch ordering; fix for multi-module projects

parent eef0b3c2
Loading
Loading
Loading
Loading
+28 −23
Original line number Diff line number Diff line
@@ -21,9 +21,10 @@ import org.apache.maven.model.Profile;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;

@Component(role = ProjectPropertyResolver.class)
public class StandardProjectPropertyResolver implements ProjectPropertyResolver {
@Component(role = ProjectPropertyResolver.class, instantiationStrategy = "per-lookup")
public class StandardProjectPropertyResolver extends AbstractLogEnabled implements ProjectPropertyResolver {
	
	@Requirement
	private MavenSession session;
@@ -51,34 +52,38 @@ public class StandardProjectPropertyResolver implements ProjectPropertyResolver
    private Properties findPropertiesObject(String key) {
    	// search the user/cli properties first
    	Properties props = this.session.getUserProperties();
    	if (props.containsKey(key))
    	if (props.containsKey(key)) {
    	    this.getLogger().debug("Found in session user properties: " + key);
    		return props;
    	}
    	
    	MavenProject ancestor = this.project;
        while (ancestor != null) {
        	// search the profiles next; in order (FIXME maybe we should go backwards?)
    	for (Profile profile : this.project.getActiveProfiles()) {
        	for (Profile profile : ancestor.getActiveProfiles()) {
        		props = profile.getProperties();
    		if (props.containsKey(key))
        		if (props.containsKey(key)) {
                    this.getLogger().debug("Found in project profile properties: " + ancestor.getArtifact() + ": " + profile.getId() + ": " + key);
        			return props;
        		}
        	}
        	
        	// now look at the project props
    	props = this.project.getProperties();
		if (props.containsKey(key))
			return props;
		
		// now recursively look up the parent project props
		MavenProject ancestor = this.project.getParent();
		while (ancestor != null) {
        	props = ancestor.getProperties();
			if (props.containsKey(key))
    		if (props.containsKey(key)) {
                this.getLogger().debug("Found in project properties: " + ancestor.getArtifact() + ": " + key);
    			return props;
    		}

            ancestor = ancestor.getParent();
        }

    	// search the system properties last (FIXME is this right?)
    	props = this.session.getSystemProperties();
    	if (props.containsKey(key))
    	if (props.containsKey(key)) {
            this.getLogger().debug("Found in system properties: " + key);
    		return props;
    	}
		
		return null;
    }