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

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

Introduction

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

Prototype

public String getArtifactId() 

Source Link

Usage

From source file:org.jfrog.jade.plugins.idea.IdeaModuleMojo.java

License:Apache License

/**
 * Adds the Web module to the (.iml) project file.
 *
 * @param module Xpp3Dom element/* w  w  w.j  ava2 s.  co m*/
 */
private void addWebModule(Element module) {
    // TODO: this is bad - reproducing war plugin defaults, etc!
    //   --> this is where the OGNL out of a plugin would be helpful as we could run package first and
    //       grab stuff from the mojo

    MavenProject executedProject = getExecutedProject();
    String warWebapp = executedProject.getBuild().getDirectory() + "/" + executedProject.getArtifactId();
    String warSrc = getPluginSetting("maven-war-plugin", "warSourceDirectory", "src/main/webapp");
    String webXml = warSrc + "/WEB-INF/web.xml";

    module.addAttribute("type", "J2EE_WEB_MODULE");

    Element component = findComponent(module, "WebModuleBuildComponent");
    Element setting = findSetting(component, "EXPLODED_URL");
    setting.addAttribute("value", getModuleFileUrl(warWebapp));

    component = findComponent(module, "WebModuleProperties");

    removeOldElements(component, "containerElement");
    List artifacts = executedProject.getTestArtifacts();
    for (Iterator i = artifacts.iterator(); i.hasNext();) {
        Artifact artifact = (Artifact) i.next();

        Element containerElement = createElement(component, "containerElement");

        if (isLinkModules() && isReactorProject(artifact.getGroupId(), artifact.getArtifactId())) {
            containerElement.addAttribute("type", "module");
            containerElement.addAttribute("name", getNameProvider().getProjectName(artifact));
            Element methodAttribute = createElement(containerElement, "attribute");
            methodAttribute.addAttribute("name", "method");
            methodAttribute.addAttribute("value", "5");
            Element uriAttribute = createElement(containerElement, "attribute");
            uriAttribute.addAttribute("name", "URI");
            // TODO: Find a way to get this info from the war plugin
            uriAttribute.addAttribute("value",
                    "/WEB-INF/lib/" + artifact.getArtifactId() + "-" + artifact.getVersion() + ".jar");
        } else if (artifact.getFile() != null) {
            containerElement.addAttribute("type", "library");
            containerElement.addAttribute("level", "module");
            Element methodAttribute = createElement(containerElement, "attribute");
            methodAttribute.addAttribute("name", "method");
            if (Artifact.SCOPE_PROVIDED.equalsIgnoreCase(artifact.getScope())) {
                methodAttribute.addAttribute("value", "0");// If scope is provided, do not package.
            } else {
                methodAttribute.addAttribute("value", "1");// IntelliJ 5.0.2 is bugged and doesn't read it
            }
            Element uriAttribute = createElement(containerElement, "attribute");
            uriAttribute.addAttribute("name", "URI");
            uriAttribute.addAttribute("value", "/WEB-INF/lib/" + artifact.getFile().getName());
            Element url = createElement(containerElement, "url");
            url.setText(getLibraryUrl(artifact));
        }
    }

    addDeploymentDescriptor(component, "web.xml", "2.3", webXml);

    Element element = findElement(component, "webroots");
    removeOldElements(element, "root");

    element = createElement(element, "root");
    element.addAttribute("relative", "/");
    element.addAttribute("url", getModuleFileUrl(warSrc));
}

From source file:org.jfrog.jade.plugins.idea.IdeaModuleMojo.java

License:Apache License

private boolean isReactorProject(String groupId, String artifactId) {
    List reactorProjects = getReactorProjects();
    if (reactorProjects != null) {
        for (Iterator j = reactorProjects.iterator(); j.hasNext();) {
            MavenProject p = (MavenProject) j.next();
            if (p.getGroupId().equals(groupId) && p.getArtifactId().equals(artifactId)) {
                return true;
            }//w  w  w  . java2 s  . c  om
        }
    }
    return false;
}

From source file:org.jfrog.jade.plugins.natives.plugin.NativeCompileMojo.java

License:Open Source License

public MavenProject findInReactorList(Artifact artifact) {
    for (MavenProject reactorProject : reactorProjects) {
        if (reactorProject.getGroupId().equals(artifact.getGroupId())
                && reactorProject.getArtifactId().equals(artifact.getArtifactId())
                && reactorProject.getVersion().equals(artifact.getVersion())) {
            return reactorProject;
        }/*from   ww w  .jav  a  2 s . c  o  m*/
    }
    return null;
}

From source file:org.jfrog.jade.plugins.natives.plugin.NativeNameProvider.java

License:Apache License

public String getProjectName(MavenProject project) {
    Artifact artifact = project.getArtifact();
    boolean isLib = isLibrary(artifact);
    return getProjectName(project.getGroupId(), project.getArtifactId(), isLib);
}

From source file:org.johnstonshome.maven.pkgdep.goal.ExportGoal.java

License:Open Source License

/**
 * {@inheritDoc}//from w w  w. j  av  a  2s.  c  o  m
 */
public void execute() throws MojoExecutionException {

    /*
     * The list of all discovered packages.
     */
    final List<Package> packages = new LinkedList<Package>();

    /*
     * Copy of the Maven local POM
     */
    final MavenProject project = (MavenProject) this.getPluginContext().get("project");

    /*
     * The default target for any discovered package.
     */
    final Artifact thisBundle = new Artifact(project.getGroupId(), project.getArtifactId(),
            new VersionNumber(project.getVersion()));

    /*
     * The parser for Export-Package decalarations.
     */
    final ImportExportParser parser = new ImportExportParser();

    /*
     * Find any static MANIFEST.MF file(s)
     */
    getLog().info(String.format("Processing %s files...", MANIFEST_FILE));
    if (project.getBuild().getResources() != null) {
        for (final Object resource : project.getBuild().getResources()) {
            final File resourceDir = new File(((Resource) resource).getDirectory());
            final File[] manifests = resourceDir.listFiles(new FilenameFilter() {
                public boolean accept(final File dir, final String name) {
                    return name.equals(MANIFEST_FILE);
                }
            });
            for (final File manifest : manifests) {
                getLog().info(manifest.getPath());
                packages.addAll(parser.parseManifestExports(manifest, project.getBuild().getSourceDirectory(),
                        thisBundle));
            }
        }
    }

    /*
     * Look for the felix bundle plugin
     */
    getLog().info(String.format("Processing %s content...", ImportExportParser.PLUGIN_ARTIFACT));
    packages.addAll(parser.parsePomExports(project, thisBundle));

    final Repository repository = new Repository();

    for (final Package found : packages) {
        getLog().info(found.getName() + ":" + found.getVersions());
        final Package local = repository.readPackage(found.getName());
        if (local != null) {
            local.merge(found);
            repository.writePackage(local);
        } else {
            repository.writePackage(found);
        }
    }
}

From source file:org.jszip.maven.AbstractJSZipMojo.java

License:Apache License

protected MavenProject findProject(List<MavenProject> projects, Artifact artifact) {
    for (MavenProject project : projects) {
        if (StringUtils.equals(artifact.getGroupId(), project.getGroupId())
                && StringUtils.equals(artifact.getArtifactId(), project.getArtifactId())
                && StringUtils.equals(artifact.getVersion(), project.getVersion())) {
            return project;
        }//from   w w  w .ja v  a  2 s  . co  m
    }
    return null;
}

From source file:org.jszip.maven.RunMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    if (runPackages == null || runPackages.length == 0) {
        runPackages = new String[] { "war" };
    }/*from   w ww .java 2  s  .c  om*/

    injectMissingArtifacts(project, executedProject);

    if (!Arrays.asList(runPackages).contains(project.getPackaging())) {
        getLog().info("Skipping JSZip run: module "
                + ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId())
                + " as not specified in runPackages");
        return;
    }
    if (StringUtils.isNotBlank(runModule) && !project.getArtifactId().equals(runModule)
            && !ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()).equals(runModule)) {
        getLog().info("Skipping JSZip run: module "
                + ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId())
                + " as requested runModule is " + runModule);
        return;
    }
    getLog().info("Starting JSZip run: module "
            + ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()));
    MavenProject project = this.project;
    long lastResourceChange = System.currentTimeMillis();
    long lastClassChange = System.currentTimeMillis();
    long lastPomChange = getPomsLastModified();

    Server server = new Server();
    if (connectors == null || connectors.length == 0) {
        SelectChannelConnector selectChannelConnector = new SelectChannelConnector();
        selectChannelConnector.setPort(8080);
        connectors = new Connector[] { selectChannelConnector };
    }
    server.setConnectors(connectors);
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    HandlerCollection handlerCollection = new HandlerCollection(true);
    DefaultHandler defaultHandler = new DefaultHandler();
    handlerCollection.setHandlers(new Handler[] { contexts, defaultHandler });
    server.setHandler(handlerCollection);
    try {
        server.start();
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    List<MavenProject> reactorProjects = this.reactorProjects;
    WebAppContext webAppContext;
    Resource webXml;
    List<Resource> resources;
    try {
        resources = new ArrayList<Resource>();
        addCssEngineResources(project, reactorProjects, mappings, resources);
        for (Artifact a : getOverlayArtifacts(project, scope)) {
            addOverlayResources(reactorProjects, resources, a);
        }
        if (warSourceDirectory == null) {
            warSourceDirectory = new File(project.getBasedir(), "src/main/webapp");
        }
        if (warSourceDirectory.isDirectory()) {
            resources.add(Resource.newResource(warSourceDirectory));
        }
        Collections.reverse(resources);
        getLog().debug("Overlays:");
        int index = 0;
        for (Resource r : resources) {
            getLog().debug("  [" + index++ + "] = " + r);
        }
        final ResourceCollection resourceCollection = new ResourceCollection(
                resources.toArray(new Resource[resources.size()]));

        webAppContext = new JettyWebAppContext();
        webAppContext.setWar(warSourceDirectory.getAbsolutePath());
        webAppContext.setBaseResource(resourceCollection);

        WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
        for (String s : getClasspathElements(project, scope)) {
            classLoader.addClassPath(s);
        }
        webAppContext.setClassLoader(classLoader);

        contexts.setHandlers(new Handler[] { webAppContext });
        contexts.start();
        webAppContext.start();
        Resource webInf = webAppContext.getWebInf();
        webXml = webInf != null ? webInf.getResource("web.xml") : null;
    } catch (MojoExecutionException e) {
        throw e;
    } catch (MojoFailureException e) {
        throw e;
    } catch (ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (MalformedURLException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

    long webXmlLastModified = webXml == null ? 0L : webXml.lastModified();
    try {

        getLog().info("Context started. Will restart if changes to poms detected.");
        long nextClasspathCheck = System.currentTimeMillis() + classpathCheckInterval;
        while (true) {
            long nextCheck = System.currentTimeMillis() + 500;
            long pomsLastModified = getPomsLastModified();
            boolean pomsChanged = lastPomChange < pomsLastModified;
            boolean overlaysChanged = false;
            boolean classPathChanged = webXmlLastModified < (webXml == null ? 0L : webXml.lastModified());
            if (nextClasspathCheck < System.currentTimeMillis()) {
                long classChange = classpathLastModified(project);
                if (classChange > lastClassChange) {
                    classPathChanged = true;
                    lastClassChange = classChange;
                }
                nextClasspathCheck = System.currentTimeMillis() + classpathCheckInterval;
            }
            if (!classPathChanged && !overlaysChanged && !pomsChanged) {

                try {
                    lastResourceChange = processResourceSourceChanges(reactorProjects, project,
                            lastResourceChange);
                } catch (ArtifactFilterException e) {
                    getLog().debug("Couldn't process resource changes", e);
                }
                try {
                    Thread.sleep(Math.max(100L, nextCheck - System.currentTimeMillis()));
                } catch (InterruptedException e) {
                    getLog().debug("Interrupted", e);
                }
                continue;
            }
            if (pomsChanged) {
                getLog().info("Change in poms detected, re-parsing to evaluate impact...");
                // we will now process this change,
                // so from now on don't re-process
                // even if we have issues processing
                lastPomChange = pomsLastModified;
                List<MavenProject> newReactorProjects;
                try {
                    newReactorProjects = buildReactorProjects();
                } catch (ProjectBuildingException e) {
                    getLog().info("Re-parse aborted due to malformed pom.xml file(s)", e);
                    continue;
                } catch (CycleDetectedException e) {
                    getLog().info("Re-parse aborted due to dependency cycle in project model", e);
                    continue;
                } catch (DuplicateProjectException e) {
                    getLog().info("Re-parse aborted due to duplicate projects in project model", e);
                    continue;
                } catch (Exception e) {
                    getLog().info("Re-parse aborted due a problem that prevented sorting the project model", e);
                    continue;
                }
                if (!buildPlanEqual(newReactorProjects, this.reactorProjects)) {
                    throw new BuildPlanModifiedException("A pom.xml change has impacted the build plan.");
                }
                MavenProject newProject = findProject(newReactorProjects, this.project);
                if (newProject == null) {
                    throw new BuildPlanModifiedException("A pom.xml change appears to have removed "
                            + this.project.getId() + " from the build plan.");
                }

                newProject.setArtifacts(resolve(newProject, "runtime"));

                getLog().debug("Comparing effective classpath of new and old models");
                try {
                    classPathChanged = classPathChanged || classpathsEqual(project, newProject, scope);
                } catch (DependencyResolutionRequiredException e) {
                    getLog().info("Re-parse aborted due to dependency resolution problems", e);
                    continue;
                }
                if (classPathChanged) {
                    getLog().info("Effective classpath of " + project.getId() + " has changed.");
                } else {
                    getLog().debug("Effective classpath is unchanged.");
                }

                getLog().debug("Comparing effective overlays of new and old models");
                try {
                    overlaysChanged = overlaysEqual(project, newProject);
                } catch (OverConstrainedVersionException e) {
                    getLog().info("Re-parse aborted due to dependency resolution problems", e);
                    continue;
                } catch (ArtifactFilterException e) {
                    getLog().info("Re-parse aborted due to overlay resolution problems", e);
                    continue;
                }
                if (overlaysChanged) {
                    getLog().info("Overlay modules of " + project.getId() + " have changed.");
                } else {
                    getLog().debug("Overlay modules are unchanged.");
                }

                getLog().debug("Comparing overlays paths of new and old models");
                try {
                    List<Resource> newResources = new ArrayList<Resource>();
                    // TODO newMappings
                    addCssEngineResources(newProject, newReactorProjects, mappings, resources);
                    for (Artifact a : getOverlayArtifacts(project, scope)) {
                        addOverlayResources(newReactorProjects, newResources, a);
                    }
                    if (warSourceDirectory.isDirectory()) {
                        newResources.add(Resource.newResource(warSourceDirectory));
                    }
                    Collections.reverse(newResources);
                    getLog().debug("New overlays:");
                    int index = 0;
                    for (Resource r : newResources) {
                        getLog().debug("  [" + index++ + "] = " + r);
                    }
                    boolean overlayPathsChanged = !resources.equals(newResources);
                    if (overlayPathsChanged) {
                        getLog().info("Overlay module paths of " + project.getId() + " have changed.");
                    } else {
                        getLog().debug("Overlay module paths are unchanged.");
                    }
                    overlaysChanged = overlaysChanged || overlayPathsChanged;
                } catch (ArtifactFilterException e) {
                    getLog().info("Re-parse aborted due to overlay evaluation problems", e);
                    continue;
                } catch (PluginConfigurationException e) {
                    getLog().info("Re-parse aborted due to overlay evaluation problems", e);
                    continue;
                } catch (PluginContainerException e) {
                    getLog().info("Re-parse aborted due to overlay evaluation problems", e);
                    continue;
                } catch (IOException e) {
                    getLog().info("Re-parse aborted due to overlay evaluation problems", e);
                    continue;
                }

                project = newProject;
                reactorProjects = newReactorProjects;
            }

            if (!overlaysChanged && !classPathChanged) {
                continue;
            }
            getLog().info("Restarting context to take account of changes...");
            try {
                webAppContext.stop();
            } catch (Exception e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }

            if (classPathChanged) {
                getLog().info("Updating classpath...");
                try {
                    WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
                    for (String s : getClasspathElements(project, scope)) {
                        classLoader.addClassPath(s);
                    }
                    webAppContext.setClassLoader(classLoader);
                } catch (Exception e) {
                    throw new MojoExecutionException(e.getMessage(), e);
                }
            }

            if (overlaysChanged || classPathChanged) {
                getLog().info("Updating overlays...");
                try {
                    resources = new ArrayList<Resource>();
                    addCssEngineResources(project, reactorProjects, mappings, resources);
                    for (Artifact a : getOverlayArtifacts(project, scope)) {
                        addOverlayResources(reactorProjects, resources, a);
                    }
                    if (warSourceDirectory.isDirectory()) {
                        resources.add(Resource.newResource(warSourceDirectory));
                    }
                    Collections.reverse(resources);
                    getLog().debug("Overlays:");
                    int index = 0;
                    for (Resource r : resources) {
                        getLog().debug("  [" + index++ + "] = " + r);
                    }
                    final ResourceCollection resourceCollection = new ResourceCollection(
                            resources.toArray(new Resource[resources.size()]));
                    webAppContext.setBaseResource(resourceCollection);
                } catch (Exception e) {
                    throw new MojoExecutionException(e.getMessage(), e);
                }
            }
            try {
                webAppContext.start();
            } catch (Exception e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
            webXmlLastModified = webXml == null ? 0L : webXml.lastModified();
            getLog().info("Context restarted.");
        }

    } finally {
        try {
            server.stop();
        } catch (Exception e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
}

From source file:org.jszip.maven.RunMojo.java

License:Apache License

private void injectMissingArtifacts(MavenProject destination, MavenProject source) {
    if (destination.getArtifact().getFile() == null && source.getArtifact().getFile() != null) {
        getLog().info("Pushing primary artifact from forked execution into current execution");
        destination.getArtifact().setFile(source.getArtifact().getFile());
    }// w  w  w  .  jav a2  s . c  o  m
    for (Artifact executedArtifact : source.getAttachedArtifacts()) {
        String executedArtifactId = (executedArtifact.getClassifier() == null ? "."
                : "-" + executedArtifact.getClassifier() + ".") + executedArtifact.getType();
        if (StringUtils.equals(executedArtifact.getGroupId(), destination.getGroupId())
                && StringUtils.equals(executedArtifact.getArtifactId(), destination.getArtifactId())
                && StringUtils.equals(executedArtifact.getVersion(), destination.getVersion())) {
            boolean found = false;
            for (Artifact artifact : destination.getAttachedArtifacts()) {
                if (StringUtils.equals(artifact.getGroupId(), destination.getGroupId())
                        && StringUtils.equals(artifact.getArtifactId(), destination.getArtifactId())
                        && StringUtils.equals(artifact.getVersion(), destination.getVersion())
                        && StringUtils.equals(artifact.getClassifier(), executedArtifact.getClassifier())
                        && StringUtils.equals(artifact.getType(), executedArtifact.getType())) {
                    if (artifact.getFile() == null) {
                        getLog().info("Pushing " + executedArtifactId
                                + " artifact from forked execution into current execution");
                        artifact.setFile(executedArtifact.getFile());
                    }
                    found = true;
                }
            }
            if (!found) {
                getLog().info("Attaching " + executedArtifactId
                        + " artifact from forked execution into current execution");
                projectHelper.attachArtifact(destination, executedArtifact.getType(),
                        executedArtifact.getClassifier(), executedArtifact.getFile());
            }
        }
    }
}

From source file:org.jvnet.hudson.maven3.listeners.MavenProjectInfo.java

License:Apache License

public MavenProjectInfo(MavenProject mavenProject) {
    this.displayName = mavenProject.getName();
    this.groupId = mavenProject.getGroupId();
    this.artifactId = mavenProject.getArtifactId();
    this.version = mavenProject.getVersion();
}

From source file:org.jvnet.hudson.plugins.mavendepsupdate.MavenDependencyUpdateTrigger.java

License:Apache License

private Map<String, MavenProject> getProjectMap(List<MavenProject> projects) {
    Map<String, MavenProject> index = new LinkedHashMap<String, MavenProject>();

    for (MavenProject project : projects) {
        String projectId = ArtifactUtils.key(project.getGroupId(), project.getArtifactId(),
                project.getVersion());//from www  .java  2s . c  om
        index.put(projectId, project);
    }

    return index;
}