Java Code Examples for org.apache.maven.project.MavenProject#getPackaging()

The following examples show how to use org.apache.maven.project.MavenProject#getPackaging() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSetQualifierMojo.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected void syncModule ( final MavenProject project, final String version ) throws Exception
{
    final String packaging = project.getPackaging ();
    getLog ().debug ( "Project type: " + packaging );
    if ( "eclipse-plugin".equals ( packaging ) )
    {
        handleBundle ( project, version );
    }
    else if ( "eclipse-feature".equals ( packaging ) )
    {
        handleFeature ( project, version );
    }
    else if ( "eclipse-repository".equals ( packaging ) )
    {
        handleRepository ( project, version );
    }
    else if ( "eclipse-test-plugin".equals ( packaging ) )
    {
        handleBundle ( project, version );
    }
}
 
Example 2
Source File: UpdateMojo.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected String findVersion ( final String id )
{
    getLog ().debug ( String.format ( "Looking for '%s'", id ) );
    for ( final MavenProject p : getReactorProjects () )
    {
        final String artifactId = p.getArtifactId ();
        final String packaging = p.getPackaging ();

        getLog ().debug ( String.format ( "Found %s:%s:%s:%s", p.getGroupId (), p.getArtifactId (), p.getVersion (), p.getPackaging () ) );

        if ( "eclipse-plugin".equals ( packaging ) && artifactId.equals ( id ) )
        {
            return getVersion ( p );
        }
        if ( "eclipse-feature".equals ( packaging ) && ( artifactId + ".feature.group" ).equals ( id ) )
        {
            return getVersion ( p );
        }
    }

    throw new IllegalStateException ( String.format ( "Unable to find installable unit: %s", id ) );
}
 
Example 3
Source File: DockerAssemblyManager.java    From docker-maven-plugin with Apache License 2.0 6 votes vote down vote up
private File ensureThatArtifactFileIsSet(MavenProject project) {
    Artifact artifact = project.getArtifact();
    if (artifact == null) {
        return null;
    }
    File oldFile = artifact.getFile();
    if (oldFile != null) {
        return oldFile;
    }
    Build build = project.getBuild();
    if (build == null) {
        return null;
    }
    String finalName = build.getFinalName();
    String target = build.getDirectory();
    if (finalName == null || target == null) {
        return null;
    }
    File artifactFile = new File(target, finalName + "." + project.getPackaging());
    if (artifactFile.exists() && artifactFile.isFile()) {
        setArtifactFile(project, artifactFile);
    }
    return null;
}
 
Example 4
Source File: FlexMavenPackagedProjectStagingDelegate.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static IPath getFinalArtifactPath(IProject project) throws CoreException {
  IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
  IMavenProjectFacade projectFacade = projectManager.create(project, new NullProgressMonitor());
  MavenProject mavenProject = projectFacade.getMavenProject(new NullProgressMonitor());

  String buildDirectory = mavenProject.getBuild().getDirectory();
  String finalName = mavenProject.getBuild().getFinalName();
  String finalArtifactPath = buildDirectory + "/" + finalName + "." + mavenProject.getPackaging();
  return new Path(finalArtifactPath);
}
 
Example 5
Source File: DisplayPluginUpdatesMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Find optional mojos for lifecycle.
 *
 * @param project the project
 * @param lifecycle the lifecycle
 * @return the list
 * @throws LifecycleExecutionException the lifecycle execution exception
 * @throws PluginNotFoundException the plugin not found exception
 */
private List<String> findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle )
    throws LifecycleExecutionException, PluginNotFoundException
{
    String packaging = project.getPackaging();
    List<String> optionalMojos = null;

    LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging,
                                                           session.getSettings(), session.getLocalRepository() );

    if ( m != null )
    {
        optionalMojos = m.getOptionalMojos( lifecycle.getId() );
    }

    if ( optionalMojos == null )
    {
        try
        {
            m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
            optionalMojos = m.getOptionalMojos( lifecycle.getId() );
        }
        catch ( ComponentLookupException e )
        {
            getLog().debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: "
                + lifecycle.getId() + ". Error: " + e.getMessage(), e );
        }
    }

    if ( optionalMojos == null )
    {
        optionalMojos = Collections.emptyList();
    }

    return optionalMojos;
}
 
Example 6
Source File: DeployMojoSupport.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
protected String getAppFileName(MavenProject project) {
    String name = project.getBuild().getFinalName() + "." + project.getPackaging();
    if (project.getPackaging().equals("liberty-assembly")) {
        name = project.getBuild().getFinalName() + ".war";
    }
    if (stripVersion) {
        name = stripVersionFromName(name, project.getVersion());
    }
    return name;
}
 
Example 7
Source File: DeployMojo.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
private void installLooseApplication(MavenProject proj) throws Exception {
    String looseConfigFileName = getLooseConfigFileName(proj);
    String application = looseConfigFileName.substring(0, looseConfigFileName.length() - 4);
    File destDir = new File(serverDirectory, getAppsDirectory());
    File looseConfigFile = new File(destDir, looseConfigFileName);
    LooseConfigData config = new LooseConfigData();

    switch (proj.getPackaging()) {
        case "war":
            validateAppConfig(application, proj.getArtifactId());
            log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName));
            installLooseConfigWar(proj, config);
            installAndVerifyApp(config, looseConfigFile, application);
            break;
        case "ear":
            validateAppConfig(application, proj.getArtifactId());
            log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName));
            installLooseConfigEar(proj, config);
            installAndVerifyApp(config, looseConfigFile, application);
            break;
        case "liberty-assembly":
            if (mavenWarPluginExists(proj) || new File(proj.getBasedir(), "src/main/webapp").exists()) {
                validateAppConfig(application, proj.getArtifactId());
                log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName));
                installLooseConfigWar(proj, config);
                installAndVerifyApp(config, looseConfigFile, application);
            } else {
                log.debug("The liberty-assembly project does not contain the maven-war-plugin or src/main/webapp does not exist.");
            }
            break;
        default:
            log.info(MessageFormat.format(messages.getString("info.loose.application.not.supported"),
                    proj.getPackaging()));
            installApp(proj.getArtifact());
            break;
    }
}
 
Example 8
Source File: DisplayPluginUpdatesMojo.java    From versions-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Find mappings for lifecycle.
 *
 * @param project the project
 * @param lifecycle the lifecycle
 * @return the map
 * @throws LifecycleExecutionException the lifecycle execution exception
 * @throws PluginNotFoundException the plugin not found exception
 */
private Map<?,?> findMappingsForLifecycle( MavenProject project, Lifecycle lifecycle )
    throws LifecycleExecutionException, PluginNotFoundException
{
    String packaging = project.getPackaging();
    Map<?,?> mappings = null;

    LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging,
                                                           session.getSettings(), session.getLocalRepository() );
    if ( m != null )
    {
        mappings = m.getPhases( lifecycle.getId() );
    }

    Map<?,?> defaultMappings = lifecycle.getDefaultPhases();

    if ( mappings == null )
    {
        try
        {
            m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
            mappings = m.getPhases( lifecycle.getId() );
        }
        catch ( ComponentLookupException e )
        {
            if ( defaultMappings == null )
            {
                throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging
                    + "\'.", e );
            }
        }
    }

    if ( mappings == null )
    {
        if ( defaultMappings == null )
        {
            throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging
                + "\', and there is no default" );
        }
        else
        {
            mappings = defaultMappings;
        }
    }

    return mappings;
}