Example usage for org.apache.maven.project MavenProject getParent

List of usage examples for org.apache.maven.project MavenProject getParent

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getParent.

Prototype

public MavenProject getParent() 

Source Link

Document

Returns the project corresponding to a declared parent.

Usage

From source file:aQute.bnd.maven.plugin.BndMavenPlugin.java

License:Open Source License

private File loadProjectProperties(Builder builder, MavenProject project) throws Exception {
    // Load parent project properties first
    MavenProject parentProject = project.getParent();
    if (parentProject != null) {
        loadProjectProperties(builder, parentProject);
    }//from   w w  w. jav a  2 s  . c  o m

    // Merge in current project properties
    Xpp3Dom configuration = project.getGoalConfiguration("biz.aQute.bnd", "bnd-maven-plugin",
            mojoExecution.getExecutionId(), mojoExecution.getGoal());
    File baseDir = project.getBasedir();
    if (baseDir != null) { // file system based pom
        File pomFile = project.getFile();
        builder.updateModified(pomFile.lastModified(), "POM: " + pomFile);
        // check for bnd file
        String bndFileName = Project.BNDFILE;
        if (configuration != null) {
            Xpp3Dom bndfileElement = configuration.getChild("bndfile");
            if (bndfileElement != null) {
                bndFileName = bndfileElement.getValue();
            }
        }
        File bndFile = IO.getFile(baseDir, bndFileName);
        if (bndFile.isFile()) {
            logger.debug("loading bnd properties from file: {}", bndFile);
            // we use setProperties to handle -include
            builder.setProperties(bndFile.getParentFile(), builder.loadProperties(bndFile));
            return bndFile;
        }
        // no bnd file found, so we fall through
    }
    // check for bnd-in-pom configuration
    if (configuration != null) {
        Xpp3Dom bndElement = configuration.getChild("bnd");
        if (bndElement != null) {
            logger.debug("loading bnd properties from bnd element in pom: {}", project);
            UTF8Properties properties = new UTF8Properties();
            properties.load(bndElement.getValue(), project.getFile(), builder);
            if (baseDir != null) {
                String here = baseDir.toURI().getPath();
                here = Matcher.quoteReplacement(here.substring(0, here.length() - 1));
                properties = properties.replaceAll("\\$\\{\\.\\}", here);
            }
            // we use setProperties to handle -include
            builder.setProperties(baseDir, properties);
        }
    }
    return project.getFile();
}

From source file:ch.sourcepond.maven.release.pom.UpdateParent.java

License:Apache License

@Override
public void alterModel(final Context updateContext) {
    final MavenProject project = updateContext.getProject();
    final Model model = updateContext.getModel();
    final MavenProject parent = project.getParent();

    if (parent != null && isSnapshot(parent.getVersion())) {
        try {//from www  .  j  a v  a 2s.c  o  m
            final String versionToDependOn = updateContext.getVersionToDependOn(parent.getGroupId(),
                    parent.getArtifactId());
            model.getParent().setVersion(versionToDependOn);
            log.debug(format(" Parent %s rewritten to version %s", parent.getArtifactId(), versionToDependOn));
        } catch (final UnresolvedSnapshotDependencyException e) {
            updateContext.addError(ERROR_FORMAT, project.getArtifactId(), e.artifactId, parent.getVersion());
        }
    }
}

From source file:ch.sourcepond.maven.release.reactor.DefaultReactor.java

License:Apache License

public String getChangedDependencyOrNull(final MavenProject project) {
    String changedDependency = null;
    for (final ReleasableModule module : this) {
        if (module.getVersion().hasChanged()) {
            for (final Dependency dependency : project.getDependencies()) {
                if (dependency.getGroupId().equals(module.getGroupId())
                        && dependency.getArtifactId().equals(module.getArtifactId())) {
                    changedDependency = dependency.getArtifactId();
                    break;
                }//from  ww w  . j  a  va  2s  .c om
            }
            if (project.getParent() != null && (project.getParent().getGroupId().equals(module.getGroupId())
                    && project.getParent().getArtifactId().equals(module.getArtifactId()))) {
                changedDependency = project.getParent().getArtifactId();
                break;
            }
        }
        if (changedDependency != null) {
            break;
        }
    }
    return changedDependency;
}

From source file:com.bekioui.maven.plugin.client.initializer.ProjectInitializer.java

License:Apache License

@SuppressWarnings("unchecked")
public static Project initialize(MavenProject mavenProject, Properties properties)
        throws MojoExecutionException {
    String clientPackagename = mavenProject.getParent().getGroupId() + ".client";
    String contextPackageName = clientPackagename + ".context";
    String apiPackageName = clientPackagename + ".api";
    String implPackageName = clientPackagename + ".impl";
    String resourceBasedirPath = mavenProject.getBasedir().getAbsolutePath();
    String projectBasedirPath = resourceBasedirPath.substring(0,
            resourceBasedirPath.lastIndexOf(File.separator));

    File clientDirectory = new File(projectBasedirPath + File.separator + properties.clientArtifactId());
    if (clientDirectory.exists()) {
        try {/*  w ww . ja v a2  s. c  o  m*/
            FileUtils.deleteDirectory(clientDirectory);
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to delete existing client directory.", e);
        }
    }
    clientDirectory.mkdir();

    File javaSourceDirectory = new File(resourceBasedirPath + FULL_SRC_FOLDER
            + properties.resourcePackageName().replaceAll("\\.", File.separator));
    if (!javaSourceDirectory.isDirectory()) {
        throw new MojoExecutionException(
                "Java sources directory not found: " + javaSourceDirectory.getAbsolutePath());
    }

    List<String> classpathElements;
    try {
        classpathElements = mavenProject.getCompileClasspathElements();
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("Failed to get compile classpath elements.", e);
    }

    List<URL> classpaths = new ArrayList<>();
    for (String element : classpathElements) {
        try {
            classpaths.add(new File(element).toURI().toURL());
        } catch (MalformedURLException e) {
            throw new MojoExecutionException(element + " is an invalid classpath element.", e);
        }
    }

    return Project.builder() //
            .mavenProject(mavenProject) //
            .properties(properties) //
            .clientPackageName(clientPackagename) //
            .contextPackageName(contextPackageName) //
            .apiPackageName(apiPackageName) //
            .implPackageName(implPackageName) //
            .clientDirectory(clientDirectory) //
            .javaSourceDirectory(javaSourceDirectory) //
            .classpaths(classpaths) //
            .build();
}

From source file:com.bugvm.maven.plugin.AbstractBugVMMojo.java

License:Apache License

protected Config.Builder configure(Config.Builder builder) throws MojoExecutionException {
    builder.logger(getBugVMLogger());/*  www .j a  va2  s. c  o  m*/

    // load config base file if it exists (and properties)

    if (os != null) {
        builder.os(OS.valueOf(os));
    }

    if (propertiesFile != null) {
        if (!propertiesFile.exists()) {
            throw new MojoExecutionException(
                    "Invalid 'propertiesFile' specified for BugVM compile: " + propertiesFile);
        }
        try {
            getLog().debug(
                    "Including properties file in BugVM compiler config: " + propertiesFile.getAbsolutePath());
            builder.addProperties(propertiesFile);
        } catch (IOException e) {
            throw new MojoExecutionException(
                    "Failed to add properties file to BugVM config: " + propertiesFile);
        }
    } else {
        try {
            builder.readProjectProperties(project.getBasedir(), false);
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to read BugVM project properties file(s) in "
                    + project.getBasedir().getAbsolutePath(), e);
        }
    }

    if (configFile != null) {
        if (!configFile.exists()) {
            throw new MojoExecutionException("Invalid 'configFile' specified for BugVM compile: " + configFile);
        }
        try {
            getLog().debug("Loading config file for BugVM compiler: " + configFile.getAbsolutePath());
            builder.read(configFile);
        } catch (Exception e) {
            throw new MojoExecutionException("Failed to read BugVM config file: " + configFile);
        }
    } else {
        try {
            builder.readProjectConfig(project.getBasedir(), false);
        } catch (Exception e) {
            throw new MojoExecutionException(
                    "Failed to read project BugVM config file in " + project.getBasedir().getAbsolutePath(), e);
        }
    }

    // Read embedded BugVM <config> if there is one
    Plugin plugin = project.getPlugin("com.bugvm:bugvm-maven-plugin");
    MavenProject p = project;
    while (p != null && plugin == null) {
        plugin = p.getPluginManagement().getPluginsAsMap().get("com.bugvm:bugvm-maven-plugin");
        if (plugin == null)
            p = p.getParent();
    }
    if (plugin != null) {
        getLog().debug("Reading BugVM plugin configuration from " + p.getFile().getAbsolutePath());
        Xpp3Dom configDom = (Xpp3Dom) plugin.getConfiguration();
        if (configDom != null && configDom.getChild("config") != null) {
            StringWriter sw = new StringWriter();
            XMLWriter xmlWriter = new PrettyPrintXMLWriter(sw, "UTF-8", null);
            Xpp3DomWriter.write(xmlWriter, configDom.getChild("config"));
            try {
                builder.read(new StringReader(sw.toString()), project.getBasedir());
            } catch (Exception e) {
                throw new MojoExecutionException("Failed to read BugVM config embedded in POM", e);
            }
        }
    }

    File tmpDir = new File(project.getBuild().getDirectory(), "bugvm.tmp");
    try {
        FileUtils.deleteDirectory(tmpDir);
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to clean output dir " + tmpDir, e);
    }
    tmpDir.mkdirs();

    Home home = null;
    try {
        home = Home.find();
    } catch (Throwable t) {
    }
    if (home == null || !home.isDev()) {
        home = new Config.Home(unpackBugVMDist());
    }
    builder.home(home).tmpDir(tmpDir).skipInstall(true).installDir(installDir);
    if (home.isDev()) {
        builder.useDebugLibs(Boolean.getBoolean("bugvm.useDebugLibs"));
        builder.dumpIntermediates(true);
    }

    if (debug != null && !debug.equals("false")) {
        builder.debug(true);
        if (debugPort != -1) {
            builder.addPluginArgument("debug:jdwpport=" + debugPort);
        }
        if ("clientmode".equals(debug)) {
            builder.addPluginArgument("debug:clientmode=true");
        }
    }

    if (skipSigning) {
        builder.iosSkipSigning(true);
    } else {
        if (signIdentity != null) {
            getLog().debug("Using explicit signing identity: " + signIdentity);
            builder.iosSignIdentity(SigningIdentity.find(SigningIdentity.list(), signIdentity));
        }

        if (provisioningProfile != null) {
            getLog().debug("Using explicit provisioning profile: " + provisioningProfile);
            builder.iosProvisioningProfile(
                    ProvisioningProfile.find(ProvisioningProfile.list(), provisioningProfile));
        }

        // if (keychainPassword != null) {
        //     builder.keychainPassword(keychainPassword);
        // } else if (keychainPasswordFile != null) {
        //     builder.keychainPasswordFile(keychainPasswordFile);
        // }
    }

    if (cacheDir != null) {
        builder.cacheDir(cacheDir);
    }

    builder.clearClasspathEntries();

    // configure the runtime classpath

    try {
        for (Object object : project.getRuntimeClasspathElements()) {
            String path = (String) object;
            if (getLog().isDebugEnabled()) {
                getLog().debug("Including classpath element for BugVM app: " + path);
            }
            builder.addClasspathEntry(new File(path));
        }
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("Error resolving application classpath for BugVM build", e);
    }

    return builder;
}

From source file:com.ccoe.build.profiler.profile.DiscoveryProfile.java

License:Apache License

private MavenProject getParentProject(final MavenProject project, final String groupId,
        final String artifactId) {
    if (project == null) {
        return null;
    }/*from  w w w . j a  v a  2 s. co m*/
    if (project.getGroupId().equals(groupId) && project.getArtifactId().equals(artifactId)) {
        return project;
    }

    if (project.getParent() == null) {
        return null;
    }

    return getParentProject(project.getParent(), groupId, artifactId);
}

From source file:com.cloudbees.maven.license.ProcessMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    if (disableCheck)
        return;//  w w w  . java 2  s.co  m

    GroovyShell shell = createShell(LicenseScript.class);

    List<LicenseScript> comp = parseScripts(script, shell);

    if (generateLicenseHtml != null && generateLicenseXml == null) {// we need XML to be able to generate HTML
        try {
            generateLicenseXml = File.createTempFile("license", "xml");
            generateLicenseXml.deleteOnExit();
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to generate a temporary file", e);
        }
    }

    if (generateLicenseXml != null)
        comp.add((LicenseScript) shell.parse(getClass().getResourceAsStream("xmlgen.groovy"), "xmlgen.groovy"));

    if (generateLicenseHtml != null)
        comp.add((LicenseScript) shell.parse(getClass().getResourceAsStream("htmlgen.groovy"),
                "htmlgen.groovy"));

    if (inlineScript != null)
        comp.add((LicenseScript) shell.parse(inlineScript, "inlineScript"));

    for (LicenseScript s : comp) {
        s.project = project;
        s.mojo = this;
        s.run(); // setup
    }

    List<MavenProject> dependencies = new ArrayList<MavenProject>();

    // run against the project itself
    for (LicenseScript s : comp) {
        s.runCompleter(new CompleterDelegate(project, project));
    }
    dependencies.add(project);

    try {
        Map<Artifact, MavenProject> models = new HashMap<Artifact, MavenProject>();

        for (Artifact a : (Set<Artifact>) project.getArtifacts()) {
            Artifact pom = artifactFactory.createProjectArtifact(a.getGroupId(), a.getArtifactId(),
                    a.getVersion());
            MavenProject model = projectBuilder.buildFromRepository(pom,
                    project.getRemoteArtifactRepositories(), localRepository);
            models.put(a, model);
        }

        // filter them out
        for (LicenseScript s : comp) {
            s.runFilter(new FilterDelegate(models));
        }

        // filter out optional components
        for (Iterator<Entry<Artifact, MavenProject>> itr = models.entrySet().iterator(); itr.hasNext();) {
            Entry<Artifact, MavenProject> e = itr.next();
            if (e.getKey().isOptional())
                itr.remove();
        }

        for (MavenProject e : models.values()) {
            // let the completion script intercept and process the licenses
            for (LicenseScript s : comp) {
                s.runCompleter(new CompleterDelegate(e, project));
            }
        }

        dependencies.addAll(models.values());
    } catch (ProjectBuildingException e) {
        throw new MojoExecutionException("Failed to parse into dependencies", e);
    }

    if (requireCompleteLicenseInfo) {
        List<MavenProject> missing = new ArrayList<MavenProject>();
        for (MavenProject d : dependencies) {
            if (d.getLicenses().isEmpty())
                missing.add(d);
        }
        if (!missing.isEmpty()) {
            StringBuilder buf = new StringBuilder(
                    "The following dependencies are missing license information:\n");
            for (MavenProject p : missing) {
                buf.append("  " + p.getGroupId() + ':' + p.getArtifactId() + ':' + p.getVersion());
                for (p = p.getParent(); p != null; p = p.getParent())
                    buf.append(" -> " + p.getGroupId() + ':' + p.getArtifactId() + ':' + p.getVersion());
                buf.append('\n');
            }
            buf.append(
                    "\nAdd/update your completion script to fill them, or run with -Dlicense.disableCheck to bypass the check.");
            throw new MojoExecutionException(buf.toString());
        }
    }

    for (LicenseScript s : comp) {
        s.runGenerator(new GeneratorDelegate(dependencies));
    }

    if (attach) {
        if (generateLicenseXml != null)
            projectHelper.attachArtifact(project, "license.xml", null, generateLicenseXml);
        if (generateLicenseHtml != null)
            projectHelper.attachArtifact(project, "license.html", null, generateLicenseHtml);
    }
}

From source file:com.ericsson.tools.cpp.compiler.TargetCurrencyVerifier.java

License:Apache License

private void addMutableAncestorModelFiles(final Collection<File> collection, final MavenProject parent) {
    if (parent == null)
        return;//from   w ww.  j  ava  2 s  .c  o  m

    final Artifact parentPomArtifact = artifactManager.createProjectArtifact(parent);

    if (!parentPomArtifact.isSnapshot()) {
        log.debug("Parent " + parent
                + " isn't a SNAPSHOT. Ancenstry will not be searched for further mutable configurations.");
        return;
    }

    final File parentPomFile = artifactManager.getPomOfArtifact(parentPomArtifact);

    log.debug("Found mutable parent file " + parentPomFile);
    collection.add(parentPomFile);
    addMutableAncestorModelFiles(collection, parent.getParent());
}

From source file:com.exentes.maven.versions.VersionMojoUtils.java

License:Apache License

public static Map<String, Dependency> allDependenciesMap(MavenSession session) {
    Map<String, Dependency> allDependencyManagementMap = allDependencyManagementMap(session);
    Map<String, Dependency> allDependenciesMap = Maps.newHashMap();
    for (MavenProject project : session.getProjects()) {
        for (Dependency dependency : concat(emptyIfNull(project.getOriginalModel().getDependencies()),
                allActiveProfilesDependencies(project))) {
            if (dependency.getVersion() != null) {
                allDependenciesMap.put(projectDependencyKey(project, dependency), dependency);
            } else {
                // dependency version is not specified. Perhaps it is specified in a dependencyManagement section
                // of the project of one of its parents
                Dependency parentDependency = null;
                MavenProject projectToCheck = project;
                while (parentDependency == null && projectToCheck != null) {
                    parentDependency = allDependencyManagementMap
                            .get(projectDependencyKey(projectToCheck, dependency));
                    if (parentDependency != null) {
                        allDependenciesMap.put(projectDependencyKey(project, dependency), parentDependency);
                    } else {
                        if (!projectToCheck.isExecutionRoot()) {
                            projectToCheck = projectToCheck.getParent();
                        } else {
                            projectToCheck = null;
                        }/*from   w  w w  . j  ava2 s  . c  o  m*/
                    }
                }
            }
        }
    }
    return allDependenciesMap;
}

From source file:com.github.ferstl.depgraph.AggregatingGraphFactory.java

License:Apache License

private void buildModuleTree(MavenProject parentProject, DotBuilder dotBuilder) {
    @SuppressWarnings("unchecked")
    Collection<MavenProject> collectedProjects = parentProject.getCollectedProjects();
    for (MavenProject collectedProject : collectedProjects) {
        MavenProject child = collectedProject;
        MavenProject parent = collectedProject.getParent();

        while (parent != null) {
            Node parentNode = filterProject(parent);
            Node childNode = filterProject(child);

            dotBuilder.addEdge(parentNode, childNode, DottedEdgeRenderer.INSTANCE);

            // Stop if we reached the original parent project!
            if (parent.equals(parentProject)) {
                break;
            }/*ww w.  j av  a  2s  .co m*/

            child = parent;
            parent = parent.getParent();
        }
    }
}