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:cn.wanghaomiao.maven.plugin.seimi.AbstractWarMojo.java

License:Apache License

/**
 * Builds the webapp for the specified project with the new packaging task thingy
 * <p/>/*from   w w  w  .  j a va 2 s  .  co m*/
 * Classes, libraries and tld files are copied to the <tt>webappDirectory</tt> during this phase.
 *
 * @param mavenProject the maven project
 * @param webapplicationDirectory the target directory
 * @throws MojoExecutionException if an error occurred while packaging the webapp
 * @throws MojoFailureException if an unexpected error occurred while packaging the webapp
 * @throws IOException if an error occurred while copying the files
 */
@SuppressWarnings("unchecked")
public void buildWebapp(MavenProject mavenProject, File webapplicationDirectory)
        throws MojoExecutionException, MojoFailureException, IOException {

    WebappStructure cache;
    if (useCache && cacheFile.exists()) {
        // CHECKSTYLE_OFF: LineLength
        cache = new WebappStructure(mavenProject.getDependencies(),
                webappStructureSerialier.fromXml(cacheFile));
        // CHECKSTYLE_ON: LineLength
    } else {
        cache = new WebappStructure(mavenProject.getDependencies(), null);
    }

    // CHECKSTYLE_OFF: LineLength
    final long startTime = System.currentTimeMillis();
    getLog().info(
            "Assembling webapp [" + mavenProject.getArtifactId() + "] in [" + webapplicationDirectory + "]");

    final OverlayManager overlayManager = new OverlayManager(overlays, mavenProject, dependentWarIncludes,
            dependentWarExcludes, currentProjectOverlay);
    final List<WarPackagingTask> packagingTasks = getPackagingTasks(overlayManager);
    // CHECKSTYLE_ON: LineLength
    List<FileUtils.FilterWrapper> defaultFilterWrappers;
    try {
        MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
        mavenResourcesExecution.setEscapeString(escapeString);
        mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
        mavenResourcesExecution.setMavenProject(mavenProject);
        if (filters == null) {
            filters = getProject().getBuild().getFilters();
        }
        mavenResourcesExecution.setFilters(filters);
        mavenResourcesExecution.setEscapedBackslashesInFilePath(escapedBackslashesInFilePath);
        mavenResourcesExecution.setMavenSession(this.session);
        mavenResourcesExecution.setEscapeString(this.escapeString);
        mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);

        defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers(mavenResourcesExecution);

    } catch (MavenFilteringException e) {
        getLog().error("fail to build filering wrappers " + e.getMessage());
        throw new MojoExecutionException(e.getMessage(), e);
    }

    final WarPackagingContext context = new DefaultWarPackagingContext(webapplicationDirectory, cache,
            overlayManager, defaultFilterWrappers, getNonFilteredFileExtensions(),
            filteringDeploymentDescriptors, this.artifactFactory, resourceEncoding, useJvmChmod);
    for (WarPackagingTask warPackagingTask : packagingTasks) {
        warPackagingTask.performPackaging(context);
    }

    // Post packaging
    final List<WarPostPackagingTask> postPackagingTasks = getPostPackagingTasks();
    for (WarPostPackagingTask task : postPackagingTasks) {
        task.performPostPackaging(context);
    }
    getLog().info("Webapp assembled in [" + (System.currentTimeMillis() - startTime) + " msecs]");

}

From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.ClassesPackagingTask.java

License:Apache License

/**
 * @param context The warPackingContext.
 * @throws MojoExecutionException In casae of an error.
 *//*from w w w  .  jav  a 2s  .  c  o m*/
protected void generateJarArchive(WarPackagingContext context) throws MojoExecutionException {
    MavenProject project = context.getProject();
    ArtifactFactory factory = context.getArtifactFactory();
    Artifact artifact = factory.createBuildArtifact(project.getGroupId(), project.getArtifactId(),
            project.getVersion(), "jar");
    String archiveName;
    try {
        archiveName = getArtifactFinalName(context, artifact);
    } catch (InterpolationException e) {
        throw new MojoExecutionException("Could not get the final name of the artifact ["
                + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + "]",
                e);
    }
    final String targetFilename = LIB_PATH + archiveName;

    if (context.getWebappStructure().registerFile(currentProjectOverlay.getId(), targetFilename)) {
        final File libDirectory = new File(context.getWebappDirectory(), LIB_PATH);
        final File jarFile = new File(libDirectory, archiveName);
        final ClassesPackager packager = new ClassesPackager();
        packager.packageClasses(context.getClassesDirectory(), jarFile, context.getJarArchiver(),
                context.getSession(), project, context.getArchive());
    } else {
        context.getLog().warn(
                "Could not generate archive classes file [" + targetFilename + "] has already been copied.");
    }
}

From source file:co.leantechniques.maven.BuildInformation.java

License:Apache License

public Artifact getTopLevelProject() {
    MavenProject project = session.getTopLevelProject();
    return new Project(project.getGroupId(), project.getArtifactId(), project.getVersion());
}

From source file:co.leantechniques.maven.BuildInformation.java

License:Apache License

private Project projectOf(ExecutionEvent event) {
    MavenProject mavenProject = event.getProject();
    Project currentProject = new Project(mavenProject.getGroupId(), mavenProject.getArtifactId(),
            mavenProject.getVersion());//from   w ww  .j av a 2 s  .c o  m
    return projects.get(projects.indexOf(currentProject));
}

From source file:co.leantechniques.maven.BuildInformation.java

License:Apache License

private void initializeProjects(MavenSession session) {
    for (MavenProject mavenProject : session.getProjects()) {
        projects.add(new Project(mavenProject.getGroupId(), mavenProject.getArtifactId(),
                mavenProject.getVersion()));
    }/*  w w  w  .  j a  va2s .  c om*/
}

From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.RadPlugin.java

License:Open Source License

/**
 * Utility method that locates a project producing the given artifact.
 *
 * @param artifact the artifact a project should produce.
 * @return <code>true</code> if the artifact is produced by a reactor projectart.
 *///from w  w  w . j  av  a  2 s.  c  om
protected boolean isAvailableAsAReactorProject(Artifact artifact) {
    if (this.reactorProjects != null && (Constants.PROJECT_PACKAGING_JAR.equals(artifact.getType())
            || Constants.PROJECT_PACKAGING_EJB.equals(artifact.getType())
            || Constants.PROJECT_PACKAGING_WAR.equals(artifact.getType()))) {
        for (Iterator iter = this.reactorProjects.iterator(); iter.hasNext();) {
            MavenProject reactorProject = (MavenProject) iter.next();

            if (reactorProject.getGroupId().equals(artifact.getGroupId())
                    && reactorProject.getArtifactId().equals(artifact.getArtifactId())) {
                if (reactorProject.getVersion().equals(artifact.getVersion())) {
                    return true;
                } else {
                    getLog().info("Artifact " + artifact.getId()
                            + " already available as a reactor project, but with different version. Expected: "
                            + artifact.getVersion() + ", found: " + reactorProject.getVersion());
                }
            }
        }
    }
    return false;
}

From source file:com.alibaba.citrus.maven.eclipse.base.ide.AbstractIdeSupportMojo.java

License:Apache License

/**
 * Checks the list of reactor projects to see if the artifact is included.
 *
 * @param artifact the artifact to check if it is in the reactor
 * @return the reactor project or null if it is not in the reactor
 *//*w w  w.  j  av  a  2s . c  om*/
protected MavenProject getReactorProject(Artifact artifact) {
    if (reactorProjects != null) {
        for (Iterator iter = reactorProjects.iterator(); iter.hasNext();) {
            MavenProject reactorProject = (MavenProject) iter.next();

            if (reactorProject.getGroupId().equals(artifact.getGroupId())
                    && reactorProject.getArtifactId().equals(artifact.getArtifactId())) {
                if (reactorProject.getVersion().equals(artifact.getVersion())) {
                    return reactorProject;
                } else {
                    getLog().info("Artifact " + artifact.getId()
                            + " already available as a reactor project, but with different version. Expected: "
                            + artifact.getVersion() + ", found: " + reactorProject.getVersion());
                }
            }
        }
    }
    return null;
}

From source file:com.alibaba.citrus.maven.eclipse.base.ide.IdeUtils.java

License:Apache License

public static String getProjectName(String template, MavenProject project) {
    return getProjectName(template, project.getGroupId(), project.getArtifactId(), project.getVersion());
}

From source file:com.ardoq.mavenImport.ProjectSync.java

/**
 * Returns Ardoq project component ID// ww w  . ja va2 s .  com
 * @param project
 * @return
 */
private String syncProject(MavenProject project) {
    String componentName = project.getName();

    if (componentNameIdMap.containsKey(componentName)) {
        return componentNameIdMap.get(componentName);
    }

    Component ardoqProjectComponent = new Component(componentName, ardoqSync.getWorkspace().getId(), "",
            COMPONENT_TYPE_PROJECT);

    ardoqProjectComponent.setDescription(buildProjectDescription(project));

    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put("groupId", project.getGroupId());
    fields.put("artifactId", project.getArtifactId());
    fields.put("version", project.getVersion());
    mavenUtil.addLicense(project, fields);

    ardoqProjectComponent.setFields(fields);
    ardoqProjectComponent = ardoqSync.addComponent(ardoqProjectComponent);
    componentNameIdMap.put(componentName, ardoqProjectComponent.getId());

    Map<String, Integer> refTypes = ardoqSync.getModel().getReferenceTypes();

    syncProjectArtifact(project, ardoqProjectComponent, refTypes);
    syncProjectParent(project, ardoqProjectComponent, refTypes);
    syncProjectModules(project, ardoqProjectComponent, refTypes);

    return ardoqProjectComponent.getId();
}

From source file:com.ardoq.mavenImport.ProjectSync.java

private void syncProjectArtifact(MavenProject project, Component ardoqProjectComponent,
        Map<String, Integer> refTypes) {
    int refType = refTypes.get("Dependency");
    DefaultArtifact artifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), "pom",
            project.getVersion());//from  w  w  w. ja va2  s .c  o  m
    syncProjectDependencies(artifact);

    String sourceId = ardoqProjectComponent.getId();
    String targetId = artifactSync.getComponentIdFromArtifact(artifact);

    if (sourceId != null && targetId != null) {
        System.out.println("adding reference from project to artifact " + sourceId + " "
                + ardoqProjectComponent.getName() + " " + targetId + " " + artifact.getArtifactId());
        Reference ref = new Reference(ardoqSync.getWorkspace().getId(), "artifact",
                ardoqProjectComponent.getId(), targetId, refType);
        ardoqSync.addReference(ref);
    } else {
        System.err.println("Error creating reference from " + ardoqProjectComponent.getName() + " to "
                + artifact.getArtifactId() + ".. sourceId: " + sourceId + ", targetId: " + targetId);
    }
}