better property fetch ordering; fix for multi-module projects
This commit is contained in:
parent
eef0b3c2bf
commit
807db4dfb8
@ -21,9 +21,10 @@ import org.apache.maven.model.Profile;
|
|||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
|
|
||||||
@Component(role = ProjectPropertyResolver.class)
|
@Component(role = ProjectPropertyResolver.class, instantiationStrategy = "per-lookup")
|
||||||
public class StandardProjectPropertyResolver implements ProjectPropertyResolver {
|
public class StandardProjectPropertyResolver extends AbstractLogEnabled implements ProjectPropertyResolver {
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private MavenSession session;
|
private MavenSession session;
|
||||||
@ -51,34 +52,38 @@ public class StandardProjectPropertyResolver implements ProjectPropertyResolver
|
|||||||
private Properties findPropertiesObject(String key) {
|
private Properties findPropertiesObject(String key) {
|
||||||
// search the user/cli properties first
|
// search the user/cli properties first
|
||||||
Properties props = this.session.getUserProperties();
|
Properties props = this.session.getUserProperties();
|
||||||
if (props.containsKey(key))
|
if (props.containsKey(key)) {
|
||||||
return props;
|
this.getLogger().debug("Found in session user properties: " + key);
|
||||||
|
|
||||||
// search the profiles next; in order (FIXME maybe we should go backwards?)
|
|
||||||
for (Profile profile : this.project.getActiveProfiles()) {
|
|
||||||
props = profile.getProperties();
|
|
||||||
if (props.containsKey(key))
|
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
// now look at the project props
|
MavenProject ancestor = this.project;
|
||||||
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) {
|
while (ancestor != null) {
|
||||||
props = ancestor.getProperties();
|
// search the profiles next; in order (FIXME maybe we should go backwards?)
|
||||||
if (props.containsKey(key))
|
for (Profile profile : ancestor.getActiveProfiles()) {
|
||||||
|
props = profile.getProperties();
|
||||||
|
if (props.containsKey(key)) {
|
||||||
|
this.getLogger().debug("Found in project profile properties: " + ancestor.getArtifact() + ": " + profile.getId() + ": " + key);
|
||||||
return props;
|
return props;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now look at the project props
|
||||||
|
props = ancestor.getProperties();
|
||||||
|
if (props.containsKey(key)) {
|
||||||
|
this.getLogger().debug("Found in project properties: " + ancestor.getArtifact() + ": " + key);
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
ancestor = ancestor.getParent();
|
ancestor = ancestor.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
// search the system properties last (FIXME is this right?)
|
// search the system properties last (FIXME is this right?)
|
||||||
props = this.session.getSystemProperties();
|
props = this.session.getSystemProperties();
|
||||||
if (props.containsKey(key))
|
if (props.containsKey(key)) {
|
||||||
|
this.getLogger().debug("Found in system properties: " + key);
|
||||||
return props;
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user