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

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

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Default toString

Usage

From source file:net.oneandone.maven.rules.common.AbstractRule.java

License:Apache License

/**
 * Returns true if rules is defined in this project or a parent that is not part of the multi module
 *///from ww  w  .ja v  a2 s . c  om
protected boolean ruleIsDefinedInProjectOrNotModuleParent(MavenProject project, Log log) {
    if (project == null) {
        return false;
    }

    log.debug("<<< " + project.toString() + " >>>");
    log.debug("project Parent: " + project.getParent());
    log.debug("project orig Model Parent: " + project.getOriginalModel().getParent());

    if (ruleDefinedInProject(project)) {
        return true;
    } else if (!projectIsSubmodule(project, log)) {
        return ruleIsDefinedInProjectOrNotModuleParent(project.getParent(), log);
    } else {
        return false;
    }
}

From source file:org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.java

License:Open Source License

public static LifecycleMappingResult calculateLifecycleMapping(MavenProject mavenProject,
        List<MojoExecution> mojoExecutions, String lifecycleMappingId, IProgressMonitor monitor) {
    long start = System.currentTimeMillis();
    log.debug("Loading lifecycle mapping for {}.", mavenProject.toString()); //$NON-NLS-1$

    LifecycleMappingResult result = new LifecycleMappingResult();

    try {// w  w  w .  java2s.  c o  m
        if (lifecycleMappingId != null) {
            instantiateLifecycleMapping(result, mavenProject, lifecycleMappingId);
        }

        calculateEffectiveLifecycleMappingMetadata(result, mavenProject, mojoExecutions, monitor);

        if (result.getLifecycleMapping() == null) {
            lifecycleMappingId = result.getLifecycleMappingId();
            instantiateLifecycleMapping(result, mavenProject, lifecycleMappingId);
        }

        if (result.getLifecycleMapping() instanceof AbstractCustomizableLifecycleMapping) {
            instantiateProjectConfigurators(mavenProject, result, result.getMojoExecutionMapping());
        }
    } catch (CoreException ex) {
        log.error(ex.getMessage(), ex);
        result.addProblem(new MavenProblemInfo(1, ex)); // XXX that looses most of useful info
    } finally {
        log.info("Using {} lifecycle mapping for {}.", result.getLifecycleMappingId(), mavenProject.toString()); //$NON-NLS-1$
        log.debug("Loaded lifecycle mapping in {} ms for {}.", System.currentTimeMillis() - start, //$NON-NLS-1$
                mavenProject.toString());
    }
    return result;
}

From source file:org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.java

License:Open Source License

public static void calculateEffectiveLifecycleMappingMetadata(LifecycleMappingResult result,
        MavenProject mavenProject, List<MojoExecution> mojoExecutions, IProgressMonitor monitor)
        throws CoreException {

    String packagingType = mavenProject.getPackaging();
    if ("pom".equals(packagingType)) { //$NON-NLS-1$
        log.debug("Using NoopLifecycleMapping lifecycle mapping for {}.", mavenProject.toString()); //$NON-NLS-1$

        LifecycleMappingMetadata lifecycleMappingMetadata = new LifecycleMappingMetadata();
        lifecycleMappingMetadata.setLifecycleMappingId(NoopLifecycleMapping.LIFECYCLE_MAPPING_ID);

        result.setLifecycleMappingMetadata(lifecycleMappingMetadata);

        Map<MojoExecutionKey, List<IPluginExecutionMetadata>> executionMapping = new LinkedHashMap<MojoExecutionKey, List<IPluginExecutionMetadata>>();
        result.setMojoExecutionMapping(executionMapping);

        return;//from  w  w  w  . ja v a 2  s  .  c o  m
    }

    if (result.getLifecycleMapping() != null
            && !(result.getLifecycleMapping() instanceof AbstractCustomizableLifecycleMapping)) {

        String lifecycleMappingId = result.getLifecycleMapping().getId();

        log.debug("Using non-customizable lifecycle mapping {} for {}.", lifecycleMappingId,
                mavenProject.toString()); // $NON-NLS-1$

        LifecycleMappingMetadata lifecycleMappingMetadata = new LifecycleMappingMetadata();
        lifecycleMappingMetadata.setLifecycleMappingId(lifecycleMappingId);

        result.setLifecycleMappingMetadata(lifecycleMappingMetadata);

        Map<MojoExecutionKey, List<IPluginExecutionMetadata>> executionMapping = new LinkedHashMap<MojoExecutionKey, List<IPluginExecutionMetadata>>();
        result.setMojoExecutionMapping(executionMapping);

        return;
    }

    List<MappingMetadataSource> metadataSources;
    try {
        metadataSources = getProjectMetadataSources(mavenProject, getBundleMetadataSources(), mojoExecutions,
                true, monitor);
    } catch (LifecycleMappingConfigurationException e) {
        // could not read/parse/interpret mapping metadata configured in the pom or inherited from parent pom.
        // record the problem and return
        result.addProblem(new MavenProblemInfo(mavenProject, e));
        return;
    }

    calculateEffectiveLifecycleMappingMetadata(result, metadataSources, mavenProject, mojoExecutions, true,
            monitor);
}

From source file:org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.java

License:Open Source License

static void calculateEffectiveLifecycleMappingMetadata0(LifecycleMappingResult result,
        List<MappingMetadataSource> metadataSources, MavenProject mavenProject,
        List<MojoExecution> mojoExecutions, boolean applyDefaultStrategy, IProgressMonitor monitor) {

    ///* w  ww .  jav a 2s  . co  m*/
    // PHASE 1. Look for lifecycle mapping for packaging type
    //

    LifecycleMappingMetadata lifecycleMappingMetadata = null;
    MappingMetadataSource originalMetadataSource = null;

    for (int i = 0; i < metadataSources.size(); i++) {
        MappingMetadataSource source = metadataSources.get(i);
        try {
            lifecycleMappingMetadata = source.getLifecycleMappingMetadata(mavenProject.getPackaging());
            if (lifecycleMappingMetadata != null) {
                originalMetadataSource = new SimpleMappingMetadataSource(lifecycleMappingMetadata);
                metadataSources.add(i, originalMetadataSource);
                break;
            }
        } catch (DuplicateMappingException e) {
            log.error("Duplicate lifecycle mapping metadata for {}.", mavenProject.toString());
            result.addProblem(new MavenProblemInfo(1,
                    NLS.bind(Messages.LifecycleDuplicate, mavenProject.getPackaging())));
            return; // fatal error
        }
    }

    if (lifecycleMappingMetadata == null && applyDefaultStrategy) {
        lifecycleMappingMetadata = new LifecycleMappingMetadata();
        lifecycleMappingMetadata.setLifecycleMappingId("DEFAULT"); // TODO proper constant
        lifecycleMappingMetadata.setPackagingType(mavenProject.getPackaging());
    }

    // TODO if lifecycleMappingMetadata.lifecycleMappingId==null, convert to error lifecycle mapping metadata

    result.setLifecycleMappingMetadata(lifecycleMappingMetadata);

    //
    // PHASE 2. Bind project configurators to mojo executions.
    //

    Map<MojoExecutionKey, List<IPluginExecutionMetadata>> executionMapping = new LinkedHashMap<MojoExecutionKey, List<IPluginExecutionMetadata>>();

    if (mojoExecutions != null) {
        for (MojoExecution execution : mojoExecutions) {
            MojoExecutionKey executionKey = new MojoExecutionKey(execution);

            PluginExecutionMetadata primaryMetadata = null;

            // find primary mapping first
            try {
                for (MappingMetadataSource source : metadataSources) {
                    try {
                        List<PluginExecutionMetadata> metadatas = applyParametersFilter(
                                source.getPluginExecutionMetadata(executionKey), mavenProject, execution,
                                monitor);
                        for (PluginExecutionMetadata executionMetadata : metadatas) {
                            if (LifecycleMappingFactory.isPrimaryMapping(executionMetadata)) {
                                if (primaryMetadata != null) {
                                    primaryMetadata = null;
                                    throw new DuplicateMappingException();
                                }
                                primaryMetadata = executionMetadata;
                            }
                        }
                        if (primaryMetadata != null) {
                            break;
                        }
                    } catch (CoreException e) {
                        SourceLocation location = SourceLocationHelper.findLocation(mavenProject, executionKey);
                        result.addProblem(new MavenProblemInfo(location, e));
                    }
                }
            } catch (DuplicateMappingException e) {
                log.debug("Duplicate plugin execution mapping metadata for {}.", executionKey.toString());
                result.addProblem(new MavenProblemInfo(1,
                        NLS.bind(Messages.PluginExecutionMappingDuplicate, executionKey.toString())));
            }

            if (primaryMetadata != null && !isValidPluginExecutionMetadata(primaryMetadata)) {
                log.debug("Invalid plugin execution mapping metadata for {}.", executionKey.toString());
                result.addProblem(new MavenProblemInfo(1,
                        NLS.bind(Messages.PluginExecutionMappingInvalid, executionKey.toString())));
                primaryMetadata = null;
            }

            List<IPluginExecutionMetadata> executionMetadatas = new ArrayList<IPluginExecutionMetadata>();
            if (primaryMetadata != null) {
                executionMetadatas.add(primaryMetadata);

                if (primaryMetadata.getAction() == PluginExecutionAction.configurator) {
                    // attach any secondary mapping
                    for (MappingMetadataSource source : metadataSources) {
                        try {
                            List<PluginExecutionMetadata> metadatas = source
                                    .getPluginExecutionMetadata(executionKey);
                            metadatas = applyParametersFilter(metadatas, mavenProject, execution, monitor);
                            for (PluginExecutionMetadata metadata : metadatas) {
                                if (isValidPluginExecutionMetadata(metadata)) {
                                    if (metadata.getAction() == PluginExecutionAction.configurator
                                            && isSecondaryMapping(metadata, primaryMetadata)) {
                                        executionMetadatas.add(metadata);
                                    }
                                } else {
                                    log.debug("Invalid secondary lifecycle mapping metadata for {}.",
                                            executionKey.toString());
                                }
                            }
                        } catch (CoreException e) {
                            SourceLocation location = SourceLocationHelper.findLocation(mavenProject,
                                    executionKey);
                            result.addProblem(new MavenProblemInfo(location, e));
                        }
                    }
                }
            }

            // TODO valid executionMetadatas and convert to error mapping invalid enties.

            executionMapping.put(executionKey, executionMetadatas);
        }
    } else {
        log.debug("Execution plan is null, could not calculate mojo execution mapping for {}.",
                mavenProject.toString());
    }

    result.setMojoExecutionMapping(executionMapping);
}

From source file:org.eclipse.m2e.core.ui.internal.preferences.LifecycleMappingsViewer.java

License:Open Source License

private String getSourceLabel(MavenProject project, boolean detailed) {
    StringBuilder sb = new StringBuilder("pom"); //$NON-NLS-1$
    if (detailed) {
        sb.append('(').append(project.toString()).append(')');
    }/* w w  w . j  a  v  a  2 s.com*/
    return sb.toString();
}

From source file:org.eclipse.m2e.refactoring.exclude.ExcludeArtifactRefactoring.java

License:Open Source License

private IFile getFile(MavenProject project) throws CoreException {
    IFile res = M2EUtils.getPomFile(project);

    if (res == null) {
        throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID,
                NLS.bind(Messages.ExcludeArtifactRefactoring_failedToLocatePom, project.toString())));
    } else {/*from   ww  w. ja v a  2  s  .  c o m*/
        return res;
    }
}

From source file:org.eclipse.tycho.core.osgitools.AbstractTychoProject.java

License:Open Source License

public DependencyArtifacts getDependencyArtifacts(MavenProject project, TargetEnvironment environment) {
    DependencyArtifacts platform = getDependencyArtifacts(project);

    if (environment != null && platform instanceof MultiEnvironmentTargetPlatform) {
        platform = ((MultiEnvironmentTargetPlatform) platform).getPlatform(environment);

        if (platform == null) {
            throw new IllegalStateException("Unsupported runtime environment " + environment.toString()
                    + " for project " + project.toString());
        }/*from ww  w  . j av  a2  s .c  o m*/
    }

    return platform;
}

From source file:org.eclipse.tycho.core.osgitools.OsgiBundleProject.java

License:Open Source License

@Override
public void setupProject(MavenSession session, MavenProject project) {
    ArtifactKey key = readArtifactKey(project.getBasedir());

    if (key == null) {
        throw new IllegalArgumentException(
                "Missing bundle symbolic name or version for project " + project.toString());
    }//from   ww  w  .  j  a  va 2 s . c  om

    project.setContextValue(CTX_ARTIFACT_KEY, key);
}

From source file:org.eclipse.tycho.core.resolver.DefaultTargetPlatformConfigurationReader.java

License:Open Source License

public TargetPlatformConfiguration getTargetPlatformConfiguration(MavenSession session, MavenProject project) {
    TargetPlatformConfiguration result = new TargetPlatformConfiguration();

    // Use org.eclipse.tycho:target-platform-configuration/configuration/environment, if provided
    Plugin plugin = project.getPlugin("org.eclipse.tycho:target-platform-configuration");

    if (plugin != null) {
        Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
        if (configuration != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("target-platform-configuration for " + project.toString() + ":\n"
                        + configuration.toString());
            }/*from   ww  w. j a v a2  s. c o  m*/

            addTargetEnvironments(result, project, configuration);

            setTargetPlatformResolver(result, configuration);

            setTarget(result, session, project, configuration);

            setPomDependencies(result, configuration);

            setAllowConflictingDependencies(result, configuration);

            setDisableP2Mirrors(result, configuration);

            setExecutionEnvironment(result, configuration);

            readFilters(result, configuration);

            readExtraRequirements(result, configuration);

            setOptionalDependencies(result, configuration);
        }
    }

    if (result.getEnvironments().isEmpty()) {
        TychoProject projectType = projectTypes.get(project.getPackaging());
        if (projectType != null) {
            TargetEnvironment env = projectType.getImplicitTargetEnvironment(project);
            if (env != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug(
                            "Implicit target environment for " + project.toString() + ": " + env.toString());
                }

                result.addEnvironment(env);
            }
        }
    }

    if (result.getEnvironments().isEmpty()) {
        // applying defaults
        logger.warn("No explicit target runtime environment configuration. Build is platform dependent.");

        // Otherwise, use project or execution properties, if provided
        Properties properties = (Properties) project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES);

        // Otherwise, use current system os/ws/nl/arch
        String os = PlatformPropertiesUtils.getOS(properties);
        String ws = PlatformPropertiesUtils.getWS(properties);
        String arch = PlatformPropertiesUtils.getArch(properties);

        result.addEnvironment(new TargetEnvironment(os, ws, arch, null /* nl */));

        result.setImplicitTargetEnvironment(true);
    } else {
        result.setImplicitTargetEnvironment(false);
    }

    return result;
}

From source file:org.eclipse.tycho.core.resolver.DefaultTychoDependencyResolver.java

License:Open Source License

public void resolveProject(MavenSession session, MavenProject project, List<ReactorProject> reactorProjects) {
    AbstractTychoProject dr = (AbstractTychoProject) projectTypes.get(project.getPackaging());
    if (dr == null) {
        return;//ww  w  . ja  v  a  2  s  . co  m
    }

    TargetPlatformResolver resolver = targetPlatformResolverLocator.lookupPlatformResolver(project);

    // TODO 364134 cache target platform (e.g. by checking if there is already an attached target platform)
    logger.info("Computing target platform for " + project);
    TargetPlatform targetPlatform = resolver.computeTargetPlatform(session, project, reactorProjects);

    dr.setTargetPlatform(project, targetPlatform);

    TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);

    DependencyResolverConfiguration resolverConfiguration = configuration.getDependencyResolverConfiguration();

    logger.info("Resolving dependencies of " + project);
    DependencyArtifacts dependencyArtifacts = resolver.resolveDependencies(session, project, targetPlatform,
            reactorProjects, resolverConfiguration);

    if (logger.isDebugEnabled() && DebugUtils.isDebugEnabled(session, project)) {
        StringBuilder sb = new StringBuilder();
        sb.append("Resolved target platform for ").append(project).append("\n");
        dependencyArtifacts.toDebugString(sb, "  ");
        logger.debug(sb.toString());
    }

    dr.setDependencyArtifacts(session, project, dependencyArtifacts);

    logger.info("Resolving class path of " + project);
    dr.resolveClassPath(session, project);

    resolver.injectDependenciesIntoMavenModel(project, dr, dependencyArtifacts, logger);

    if (logger.isDebugEnabled() && DebugUtils.isDebugEnabled(session, project)) {
        StringBuilder sb = new StringBuilder();
        sb.append("Injected dependencies for ").append(project.toString()).append("\n");
        for (Dependency dependency : project.getDependencies()) {
            sb.append("  ").append(dependency.toString());
        }
        logger.debug(sb.toString());
    }
}