List of usage examples for org.apache.maven.project MavenProject toString
@Override
public String toString()
From source file:org.eclipse.tycho.core.resolver.DefaultTychoResolver.java
License:Open Source License
@Override public void resolveProject(MavenSession session, MavenProject project, List<ReactorProject> reactorProjects) { AbstractTychoProject dr = (AbstractTychoProject) projectTypes.get(project.getPackaging()); if (dr == null) { return;/*from w w w . ja va2 s .co m*/ } DependencyResolver resolver = dependencyResolverLocator.lookupDependencyResolver(project); logger.info("Computing target platform for " + project); TargetPlatform preliminaryTargetPlatform = resolver.computePreliminaryTargetPlatform(session, project, reactorProjects); TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project); DependencyResolverConfiguration resolverConfiguration = configuration.getDependencyResolverConfiguration(); logger.info("Resolving dependencies of " + project); DependencyArtifacts dependencyArtifacts = resolver.resolveDependencies(session, project, preliminaryTargetPlatform, 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()); } }
From source file:org.eclipse.tycho.core.utils.TychoProjectUtils.java
License:Open Source License
/** * Returns the {@link DependencyArtifacts} instance associated with the given project. * /*ww w . j a v a2 s. c om*/ * @param project * a Tycho project * @return the resolved dependencies of the given project; never <code>null</code> * @throws IllegalStateException * if the given project does not have the resolved project dependencies stored */ public static DependencyArtifacts getDependencyArtifacts(MavenProject project) throws IllegalStateException { DependencyArtifacts resolvedDependencies = (DependencyArtifacts) project .getContextValue(TychoConstants.CTX_DEPENDENCY_ARTIFACTS); if (resolvedDependencies == null) { throw new IllegalStateException(TYCHO_NOT_CONFIGURED + project.toString()); } return resolvedDependencies; }
From source file:org.eclipse.tycho.core.utils.TychoProjectUtils.java
License:Open Source License
/** * Returns the {@link TargetPlatformConfiguration} instance associated with the given project. * /*from www .j a va 2 s .c o m*/ * @param project * a Tycho project * @return the target platform configuration for the given project; never <code>null</code> * @throws IllegalStateException * if the given project does not have an associated target platform configuration */ public static TargetPlatformConfiguration getTargetPlatformConfiguration(MavenProject project) throws IllegalStateException { TargetPlatformConfiguration targetPlatformConfiguration = (TargetPlatformConfiguration) project .getContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION); if (targetPlatformConfiguration == null) { throw new IllegalStateException(TYCHO_NOT_CONFIGURED + project.toString()); } return targetPlatformConfiguration; }
From source file:org.eclipse.tycho.core.utils.TychoProjectUtils.java
License:Open Source License
public static TargetPlatform getTargetPlatform(MavenProject project) { TargetPlatform targetPlatform = (TargetPlatform) project .getContextValue(TychoConstants.CTX_TARGET_PLATFORM); if (targetPlatform == null) { throw new IllegalStateException(TYCHO_NOT_CONFIGURED + project.toString()); }/*w w w .j ava 2 s . c om*/ return targetPlatform; }
From source file:org.eclipse.tycho.extras.sourcefeature.SourceFeatureMojo.java
License:Open Source License
private Feature getSourceFeature(MavenProject project, TargetPlatform targetPlatform) throws IOException, MojoExecutionException { P2ResolverFactory factory = equinox.getService(P2ResolverFactory.class); P2Resolver p2 = factory//from w w w. j a v a2s . c o m .createResolver(new MavenLoggerAdapter(logger, DebugUtils.isDebugEnabled(session, project))); Feature feature = Feature.read(new File(project.getBuild().getDirectory(), "feature.xml")); Document document = new Document(); document.setRootNode(new Element("feature")); document.setXmlDeclaration(new XMLDeclaration("1.0", "UTF-8")); Feature sourceFeature = new Feature(document); sourceFeature.setId(feature.getId() + ".source"); sourceFeature.setVersion(feature.getVersion()); // make sure versions of sources and binary features match FeatureRef binaryRef = new FeatureRef(new Element("includes")); binaryRef.setId(feature.getId()); binaryRef.setVersion(feature.getVersion()); sourceFeature.addFeatureRef(binaryRef); List<PluginRef> missingSourcePlugins = new ArrayList<PluginRef>(); List<FeatureRef> missingSourceFeatures = new ArrayList<FeatureRef>(); // include available source bundles for (PluginRef pluginRef : feature.getPlugins()) { if (excludedPlugins.contains(pluginRef.getId())) { continue; } // version is expected to be fully expanded at this point P2ResolutionResult result = p2.resolveInstallableUnit(targetPlatform, pluginRef.getId() + ".source", pluginRef.getVersion()); if (result.getArtifacts().size() == 1) { Entry sourceBundle = result.getArtifacts().iterator().next(); PluginRef sourceRef = new PluginRef("plugin"); sourceRef.setId(sourceBundle.getId()); sourceRef.setVersion(sourceBundle.getVersion()); sourceRef.setDownloadSide(0); sourceRef.setInstallSize(0); if (pluginRef.getOs() != null) { sourceRef.setOs(pluginRef.getOs()); } if (pluginRef.getWs() != null) { sourceRef.setWs(pluginRef.getWs()); } if (pluginRef.getArch() != null) { sourceRef.setArch(pluginRef.getArch()); } sourceRef.setUnpack(false); sourceFeature.addPlugin(sourceRef); } else { missingSourcePlugins.add(pluginRef); } } // include available source features for (FeatureRef featureRef : feature.getIncludedFeatures()) { if (excludedFeatures.contains(featureRef.getId())) { continue; } String sourceId = featureRef.getId() + ".source"; P2ResolutionResult result = p2.resolveInstallableUnit(targetPlatform, sourceId + ".feature.group", featureRef.getVersion()); if (result.getArtifacts().size() == 1) { Entry entry = result.getArtifacts().iterator().next(); FeatureRef sourceRef = new FeatureRef(new Element("includes")); sourceRef.setId(sourceId); sourceRef.setVersion(entry.getVersion()); sourceFeature.addFeatureRef(sourceRef); } else { missingSourceFeatures.add(featureRef); } } if (!missingSourceFeatures.isEmpty() || !missingSourcePlugins.isEmpty()) { StringBuilder sb = new StringBuilder(); sb.append("Could not generate source feature for project " + project.toString()).append("\n"); if (!missingSourcePlugins.isEmpty()) { sb.append(" Missing sources for plugins " + missingSourcePlugins.toString()).append("\n"); } if (!missingSourceFeatures.isEmpty()) { sb.append(" Missing sources for features " + missingSourceFeatures.toString()).append("\n"); } throw new MojoExecutionException(sb.toString()); } return sourceFeature; }
From source file:org.eclipse.tycho.plugins.p2.BaselineValidator.java
License:Open Source License
public Map<String, IP2Artifact> validateAndReplace(MavenProject project, Map<String, IP2Artifact> reactorMetadata, List<Repository> baselineRepositories, BaselineMode baselineMode, BaselineReplace baselineReplace) throws IOException, MojoExecutionException { Map<String, IP2Artifact> result = reactorMetadata; if (baselineMode != disable && baselineRepositories != null && !baselineRepositories.isEmpty()) { List<MavenRepositoryLocation> _repositories = new ArrayList<MavenRepositoryLocation>(); for (Repository repository : baselineRepositories) { if (repository.getUrl() != null) { _repositories.add(new MavenRepositoryLocation(repository.getId(), repository.getUrl())); }// w ww.j a v a 2s . c o m } File baselineBasedir = new File(project.getBuild().getDirectory(), "baseline"); BaselineService baselineService = getService(BaselineService.class); Map<String, IP2Artifact> baselineMetadata = baselineService.getProjectBaseline(_repositories, reactorMetadata, baselineBasedir); if (baselineMetadata != null) { CompoundArtifactDelta delta = getDelta(baselineService, baselineMetadata, reactorMetadata); if (delta != null) { if (System.getProperties().containsKey("tycho.debug.artifactcomparator")) { File logdir = new File(project.getBuild().getDirectory(), "artifactcomparison"); log.info("Artifact comparison detailed log directory " + logdir.getAbsolutePath()); for (Map.Entry<String, ArtifactDelta> classifier : delta.getMembers().entrySet()) { if (classifier.getValue() instanceof CompoundArtifactDelta) { ((CompoundArtifactDelta) classifier.getValue()) .writeDetails(new File(logdir, classifier.getKey())); } } } if (baselineMode == fail || (baselineMode == failCommon && !isMissingOnlyDelta(delta))) { throw new MojoExecutionException(delta.getDetailedMessage()); } else { String message = log.isDebugEnabled() ? delta.getDetailedMessage() : delta.getMessage(); log.warn(project.toString() + ": " + message); } } if (baselineReplace != none) { result = new LinkedHashMap<String, IP2Artifact>(); // replace reactor artifacts with baseline ArrayList<String> replaced = new ArrayList<String>(); for (Map.Entry<String, IP2Artifact> artifact : baselineMetadata.entrySet()) { String classifier = artifact.getKey(); FileUtils.copyFile(artifact.getValue().getLocation(), reactorMetadata.get(classifier).getLocation()); result.put(classifier, artifact.getValue()); if (classifier != null) { replaced.add(classifier); } } // un-attach and delete artifacts present in reactor but not in baseline ArrayList<String> removed = new ArrayList<String>(); ArrayList<String> inconsistent = new ArrayList<String>(); for (Map.Entry<String, IP2Artifact> entry : reactorMetadata.entrySet()) { String classifier = entry.getKey(); IP2Artifact artifact = entry.getValue(); if (classifier == null || artifact == null) { continue; } if (baselineReplace == all && !baselineMetadata.containsKey(classifier)) { List<Artifact> attachedArtifacts = project.getAttachedArtifacts(); ListIterator<Artifact> iterator = attachedArtifacts.listIterator(); while (iterator.hasNext()) { if (classifier.equals(iterator.next().getClassifier())) { iterator.remove(); break; } } artifact.getLocation().delete(); removed.add(classifier); } else { inconsistent.add(classifier); result.put(classifier, artifact); } } // Reactor build can have more or less artifacts than baseline // baselineReplace==all guarantees consistency of build artifacts with baseline repository // baselineReplace==none build results are self-consistent, but maybe inconsistent with baseline // baselineReplace==common build artifacts are inconsistent if (log.isInfoEnabled()) { StringBuilder msg = new StringBuilder(); msg.append(project.toString()); msg.append("\n The main artifact has been replaced with the baseline version.\n"); if (!replaced.isEmpty()) { msg.append( " The following attached artifacts have been replaced with the baseline version: "); msg.append(replaced.toString()); msg.append("\n"); } if (!removed.isEmpty()) { msg.append( " The following attached artifacts are not present in the baseline and have been removed: "); msg.append(removed.toString()); msg.append("\n"); } log.info(msg.toString()); } } } else { log.info("No baseline version " + project); } } return result; }
From source file:org.eclipse.tycho.target.TargetPlatformMojo.java
License:Open Source License
private void getTransitivelyReferencedTychoProjects(Collection<MavenProject> candidateProjects, HashSet<GAV> consideredProjects, List<ReactorProjectIdentities> result) throws MojoExecutionException { for (MavenProject reactorProject : candidateProjects) { if (!enterProject(reactorProject, consideredProjects)) { continue; }//from www .ja va 2s.co m // check for target platform relevant build results (registered by either p2-metadata-default or attach-artifacts) File metadataXml = getAttachedArtifact(reactorProject, RepositoryLayoutHelper.CLASSIFIER_P2_METADATA); if (metadataXml == null) { continue; } File artifactXml = getAttachedArtifact(reactorProject, RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS); // found a Tycho project -> include in target platform logger.debug("Adding reactor project: " + reactorProject.toString()); ReactorProject tychoReactorProject = DefaultReactorProject.adapt(reactorProject); verifyIndexFileLocations(tychoReactorProject, metadataXml, artifactXml); result.add(tychoReactorProject.getIdentities()); getTransitivelyReferencedTychoProjects(reactorProject.getProjectReferences().values(), consideredProjects, result); } }
From source file:org.keedio.maven.plugins.shade.filter.MinijarFilter.java
License:Apache License
/** * @since 1.6// w w w. j av a 2s.c o m */ @SuppressWarnings({ "unchecked" }) public MinijarFilter(MavenProject project, Log log, List<SimpleFilter> simpleFilters) throws IOException { this.log = log; Clazzpath cp = new Clazzpath(); ClazzpathUnit artifactUnit = cp.addClazzpathUnit(new FileInputStream(project.getArtifact().getFile()), project.toString()); for (Artifact dependency : project.getArtifacts()) { addDependencyToClasspath(cp, dependency); } removable = cp.getClazzes(); removePackages(artifactUnit); removable.removeAll(artifactUnit.getClazzes()); removable.removeAll(artifactUnit.getTransitiveDependencies()); removeSpecificallyIncludedClasses(project, simpleFilters == null ? Collections.<SimpleFilter>emptyList() : simpleFilters); }
From source file:org.phenotips.tool.packager.PackageMojo.java
License:Open Source License
private String getDependencyManagementVersion(MavenProject project, String groupId, String artifactId) throws MojoExecutionException { for (Object dependencyObject : project.getDependencyManagement().getDependencies()) { Dependency dependency = (Dependency) dependencyObject; if (dependency.getGroupId().equals(groupId) && dependency.getArtifactId().equals(artifactId)) { return dependency.getVersion(); }/*from ww w . j a v a 2 s.c o m*/ } throw new MojoExecutionException( String.format("Failed to find artifact [%s:%s] in dependency management " + "for [%s]", groupId, artifactId, project.toString())); }