Search in sources :

Example 41 with Profile

use of org.apache.maven.model.Profile in project sts4 by spring-projects.

the class MavenBridge method getActiveProfiles.

private List<Profile> getActiveProfiles() throws MavenException {
    Settings settings = getSettings();
    List<String> activeProfilesIds = settings.getActiveProfiles();
    ArrayList<Profile> activeProfiles = new ArrayList<Profile>();
    for (org.apache.maven.settings.Profile settingsProfile : settings.getProfiles()) {
        if ((settingsProfile.getActivation() != null && settingsProfile.getActivation().isActiveByDefault()) || activeProfilesIds.contains(settingsProfile.getId())) {
            Profile profile = SettingsUtils.convertFromSettingsProfile(settingsProfile);
            activeProfiles.add(profile);
        }
    }
    return activeProfiles;
}
Also used : ArrayList(java.util.ArrayList) Settings(org.apache.maven.settings.Settings) Profile(org.apache.maven.model.Profile)

Example 42 with Profile

use of org.apache.maven.model.Profile in project unleash-maven-plugin by shillner.

the class CheckPluginDependencyVersions method getSnapshotsFromAllProfiles.

// IDEA implement to use active profiles only (maybe create the effective pom using api with the release profiles)
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshotsFromAllProfiles(MavenProject project, PomPropertyResolver propertyResolver) {
    Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create();
    List<Profile> profiles = project.getModel().getProfiles();
    if (profiles != null) {
        for (Profile profile : profiles) {
            result.putAll(getSnapshotsFromManagement(profile, propertyResolver));
            result.putAll(getSnapshots(profile, propertyResolver));
        }
    }
    return result;
}
Also used : ArtifactCoordinates(com.itemis.maven.aether.ArtifactCoordinates) Profile(org.apache.maven.model.Profile)

Example 43 with Profile

use of org.apache.maven.model.Profile in project unleash-maven-plugin by shillner.

the class PomPropertyResolver method resolveAllProperties.

private void resolveAllProperties() {
    if (this.properties != null) {
        return;
    }
    this.properties = Maps.newHashMap();
    // 1. get the properties of all profiles from the settings.
    for (org.apache.maven.settings.Profile profile : this.settings.getProfiles()) {
        if (!this.profiles.contains(profile.getId())) {
            continue;
        }
        for (Map.Entry<Object, Object> entry : profile.getProperties().entrySet()) {
            this.properties.put((String) entry.getKey(), (String) entry.getValue());
        }
    }
    // 2. after that add the direct properties to override the ones of the parents
    for (Map.Entry<Object, Object> entry : this.project.getProperties().entrySet()) {
        this.properties.put((String) entry.getKey(), (String) entry.getValue());
    }
    // 3. get all properties of all activated profiles
    for (Profile profile : this.project.getModel().getProfiles()) {
        if (!this.profiles.contains(profile.getId())) {
            continue;
        }
        for (Map.Entry<Object, Object> entry : profile.getProperties().entrySet()) {
            this.properties.put((String) entry.getKey(), (String) entry.getValue());
        }
    }
    // 4. Adding all environment variables
    for (Map.Entry<String, String> sysEnv : System.getenv().entrySet()) {
        this.properties.put("env." + sysEnv.getKey(), sysEnv.getValue());
    }
    // 5. Adding all command line properties
    this.additionalProperties.forEach((k, v) -> this.properties.put((String) k, (String) v));
    // 6. special properties
    this.properties.put("project.version", this.project.getVersion());
    // now resolve property references within the properties
    for (String propertyKey : this.properties.keySet()) {
        this.properties.put(propertyKey, resolveProperty(propertyKey));
    }
}
Also used : Map(java.util.Map) Profile(org.apache.maven.model.Profile)

Example 44 with Profile

use of org.apache.maven.model.Profile in project maven-plugins by apache.

the class AntBuildWriter method getUninterpolatedSystemPath.

private String getUninterpolatedSystemPath(Artifact artifact) {
    String managementKey = artifact.getDependencyConflictId();
    for (Dependency dependency : project.getOriginalModel().getDependencies()) {
        if (managementKey.equals(dependency.getManagementKey())) {
            return dependency.getSystemPath();
        }
    }
    for (Profile profile : project.getOriginalModel().getProfiles()) {
        for (Dependency dependency : profile.getDependencies()) {
            if (managementKey.equals(dependency.getManagementKey())) {
                return dependency.getSystemPath();
            }
        }
    }
    String path = artifact.getFile().getAbsolutePath();
    Properties props = new Properties();
    props.putAll(project.getProperties());
    props.putAll(executionProperties);
    props.remove("user.dir");
    props.put("basedir", project.getBasedir().getAbsolutePath());
    SortedMap<String, String> candidateProperties = new TreeMap<String, String>();
    for (Object o : props.keySet()) {
        String key = (String) o;
        String value = new File(props.getProperty(key)).getPath();
        if (path.startsWith(value) && value.length() > 0) {
            candidateProperties.put(value, key);
        }
    }
    if (!candidateProperties.isEmpty()) {
        String value = candidateProperties.lastKey();
        String key = candidateProperties.get(value);
        path = path.substring(value.length());
        path = path.replace('\\', '/');
        return "${" + key + "}" + path;
    }
    return path;
}
Also used : Dependency(org.apache.maven.model.Dependency) Properties(java.util.Properties) TreeMap(java.util.TreeMap) File(java.io.File) Profile(org.apache.maven.model.Profile)

Example 45 with Profile

use of org.apache.maven.model.Profile in project maven-plugins by apache.

the class AbstractInvokerMojo method collectProjects.

/**
 * Collects all projects locally reachable from the specified project. The method will as such try to read the POM
 * and recursively follow its parent/module elements.
 *
 * @param projectsDir The base directory of all projects, must not be <code>null</code>.
 * @param projectPath The relative path of the current project, can denote either the POM or its base directory,
 *            must not be <code>null</code>.
 * @param projectPaths The set of already collected projects to add new projects to, must not be <code>null</code>.
 *            This set will hold the relative paths to either a POM file or a project base directory.
 * @param included A flag indicating whether the specified project has been explicitly included via the parameter
 *            {@link #pomIncludes}. Such projects will always be added to the result set even if there is no
 *            corresponding POM.
 * @throws org.apache.maven.plugin.MojoExecutionException If the project tree could not be traversed.
 */
private void collectProjects(File projectsDir, String projectPath, Collection<String> projectPaths, boolean included) throws MojoExecutionException {
    projectPath = projectPath.replace('\\', '/');
    File pomFile = new File(projectsDir, projectPath);
    if (pomFile.isDirectory()) {
        pomFile = new File(pomFile, "pom.xml");
        if (!pomFile.exists()) {
            if (included) {
                projectPaths.add(projectPath);
            }
            return;
        }
        if (!projectPath.endsWith("/")) {
            projectPath += '/';
        }
        projectPath += "pom.xml";
    } else if (!pomFile.isFile()) {
        return;
    }
    if (!projectPaths.add(projectPath)) {
        return;
    }
    getLog().debug("Collecting parent/child projects of " + projectPath);
    Model model = PomUtils.loadPom(pomFile);
    try {
        String projectsRoot = projectsDir.getCanonicalPath();
        String projectDir = pomFile.getParent();
        String parentPath = "../pom.xml";
        if (model.getParent() != null && StringUtils.isNotEmpty(model.getParent().getRelativePath())) {
            parentPath = model.getParent().getRelativePath();
        }
        String parent = relativizePath(new File(projectDir, parentPath), projectsRoot);
        if (parent != null) {
            collectProjects(projectsDir, parent, projectPaths, false);
        }
        Collection<String> modulePaths = new LinkedHashSet<String>();
        modulePaths.addAll(model.getModules());
        for (Profile profile : model.getProfiles()) {
            modulePaths.addAll(profile.getModules());
        }
        for (String modulePath : modulePaths) {
            String module = relativizePath(new File(projectDir, modulePath), projectsRoot);
            if (module != null) {
                collectProjects(projectsDir, module, projectPaths, false);
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to analyze POM: " + pomFile, e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) IOException(java.io.IOException) File(java.io.File) Profile(org.apache.maven.model.Profile)

Aggregations

Profile (org.apache.maven.model.Profile)52 HashMap (java.util.HashMap)12 Model (org.apache.maven.model.Model)12 ArrayList (java.util.ArrayList)9 Dependency (org.apache.maven.model.Dependency)8 HashSet (java.util.HashSet)7 DependencyManagement (org.apache.maven.model.DependencyManagement)7 File (java.io.File)6 Activation (org.apache.maven.model.Activation)6 MavenProject (org.apache.maven.project.MavenProject)6 Project (org.commonjava.maven.ext.common.model.Project)6 Build (org.apache.maven.model.Build)5 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)5 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)5 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)5 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)5 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)4 ArtifactCoordinates (com.itemis.maven.aether.ArtifactCoordinates)3 IOException (java.io.IOException)3 Iterator (java.util.Iterator)3