Refine search
public static String versionlessKey( Artifact artifact ) { return versionlessKey( artifact.getGroupId(), artifact.getArtifactId() ); }
private boolean isSnapshot( ArtifactVersion version ) { return version != null && ArtifactUtils.isSnapshot( version.getQualifier() ); }
public Map getArtifactMap() { if ( artifactMap == null ) { artifactMap = ArtifactUtils.artifactMapByVersionlessId( getArtifacts() ); } return artifactMap; }
CacheRecord( Artifact pomArtifact, Artifact relocatedArtifact, Set<Artifact> artifacts, Map<String, Artifact> managedVersions, List<ArtifactRepository> remoteRepositories ) { this.pomArtifact = ArtifactUtils.copyArtifact( pomArtifact ); this.relocatedArtifact = ArtifactUtils.copyArtifactSafe( relocatedArtifact ); this.artifacts = ArtifactUtils.copyArtifacts( artifacts, new ArrayList<Artifact>() ); this.remoteRepositories = new ArrayList<>( remoteRepositories ); this.managedVersions = managedVersions; if ( managedVersions != null ) { this.managedVersions = ArtifactUtils.copyArtifacts( managedVersions, new LinkedHashMap<String, Artifact>() ); } File pomFile = pomArtifact.getFile(); if ( pomFile != null && pomFile.canRead() ) { this.length = pomFile.length(); this.timestamp = pomFile.lastModified(); } else { this.length = -1; this.timestamp = -1; } }
public ResolutionGroup get( Artifact artifact, boolean resolveManagedVersions, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories ) { CacheKey cacheKey = newCacheKey( artifact, resolveManagedVersions, localRepository, remoteRepositories ); CacheRecord cacheRecord = cache.get( cacheKey ); if ( cacheRecord != null && !cacheRecord.isStale() ) { Artifact pomArtifact = ArtifactUtils.copyArtifact( cacheRecord.getArtifact() ); Artifact relocatedArtifact = ArtifactUtils.copyArtifactSafe( cacheRecord.getRelocatedArtifact() ); Set<Artifact> artifacts = ArtifactUtils.copyArtifacts( cacheRecord.getArtifacts(), new LinkedHashSet<Artifact>() ); Map<String, Artifact> managedVersions = cacheRecord.getManagedVersions(); if ( managedVersions != null ) { managedVersions = ArtifactUtils.copyArtifacts( managedVersions, new LinkedHashMap<String, Artifact>() ); } return new ResolutionGroup( pomArtifact, relocatedArtifact, artifacts, managedVersions, cacheRecord.getRemoteRepositories() ); } cache.remove( cacheKey ); return null; }
public Artifact replaceWithActiveArtifact( Artifact pluginArtifact ) if ( getProjectReferences() != null && !getProjectReferences().isEmpty() ) String refId = getProjectReferenceId( pluginArtifact.getGroupId(), pluginArtifact.getArtifactId(), pluginArtifact.getVersion() ); MavenProject ref = (MavenProject) getProjectReferences().get( refId ); if ( ref != null ) if ( attached.getFile() != null && attached.getFile().exists() ) Artifact resultArtifact = ArtifactUtils.copyArtifact( attached ); resultArtifact.setScope( pluginArtifact.getScope() ); return resultArtifact;
protected void checkSnapshotDependencies() throws MojoFailureException { getLog().info("Checking for SNAPSHOT versions in dependencies."); List<String> snapshots = new ArrayList<String>(); List<String> builtArtifacts = new ArrayList<String>(); List<MavenProject> projects = mavenSession.getProjects(); for (MavenProject project : projects) { builtArtifacts.add(project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion()); List<Dependency> dependencies = project.getDependencies(); for (Dependency d : dependencies) { String id = d.getGroupId() + ":" + d.getArtifactId() + ":" + d.getVersion(); if (!builtArtifacts.contains(id) && ArtifactUtils.isSnapshot(d.getVersion())) { snapshots.add(project + " -> " + d); } } } if (!snapshots.isEmpty()) { for (String s : snapshots) { getLog().warn(s); } throw new MojoFailureException( "There is some SNAPSHOT dependencies in the project, see warnings above. Change them or ignore with `allowSnapshots` property."); } }
@SuppressWarnings("unchecked") private void validateDependencyVersions() throws MojoExecutionException, MojoFailureException { getLog().info(Messages.CompileMojo_7); final String sarlSdkGroupId = this.mavenHelper.getConfig("sarl-sdk.groupId"); //$NON-NLS-1$ final String sarlSdkArtifactId = this.mavenHelper.getConfig("sarl-sdk.artifactId"); //$NON-NLS-1$ final Map<String, Artifact> artifacts = this.mavenHelper.getSession().getCurrentProject().getArtifactMap(); final String sdkArtifactKey = ArtifactUtils.versionlessKey(sarlSdkGroupId, sarlSdkArtifactId); final Artifact sdkArtifact = artifacts.get(sdkArtifactKey); if (sdkArtifact != null) { final Set<Artifact> dependencies = this.mavenHelper.resolveDependencies(sdkArtifactKey, false); for (final Artifact dependency : dependencies) { final ArtifactVersion dependencyVersion = new DefaultArtifactVersion(dependency.getVersion()); final String dependencyKey = ArtifactUtils.versionlessKey(dependency); final ArtifactVersion currentVersion = versions.get(dependencyKey); if (currentVersion == null || dependencyVersion.compareTo(currentVersion) > 0) { final Artifact dependencyArtifact = artifacts.get(entry.getKey()); if (dependencyArtifact != null) { final ArtifactVersion dependencyVersion = new DefaultArtifactVersion(dependencyArtifact.getVersion()); if (entry.getValue().compareTo(dependencyVersion) > 0) { final String message = MessageFormat.format(Messages.CompileMojo_8, dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId(), dependencyArtifact.getVersion(), entry.getValue().toString()); getLog().error(message); hasError = true;
public static String getId( MavenProject project ) { return ArtifactUtils.key( project.getGroupId(), project.getArtifactId(), project.getVersion() ); }
protected Artifact acceptArtifact(Artifact a, List<String> siblings) { String id = getArtifactId(a); if (siblings.contains(id)) { // skip a sibling dependency if (verbose) { getLog().info("Skip sibling dependency : " + id); } return null; } if (a.isSnapshot()) { // skip snapshot getLog().warn("Skip SNAPSHOT dependency : " + id); return null; } Artifact artifact = ArtifactUtils.copyArtifact(a); // force artifact not to be treated artifact.setResolved(false); // will treate this artifact return artifact; }
setFile( project.getFile() ); if ( project.getDependencyArtifacts() != null ) setDependencyArtifacts( Collections.unmodifiableSet( project.getDependencyArtifacts() ) ); if ( project.getArtifact() != null ) setArtifact( ArtifactUtils.copyArtifact( project.getArtifact() ) );
setFile( project.getFile() ); if ( project.getDependencyArtifacts() != null ) setDependencyArtifacts( Collections.unmodifiableSet( project.getDependencyArtifacts() ) ); if ( project.getArtifact() != null ) setArtifact( ArtifactUtils.copyArtifact( project.getArtifact() ) );
public static String key( Artifact artifact ) { return key( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); }
private String checkArtifact(Artifact artifact, Map<String, String> originalReactorVersions, String type) { String versionlessArtifactKey = ArtifactUtils.versionlessKey(artifact.getGroupId(), artifact.getArtifactId()); boolean isSnapshot = (artifact.isSnapshot() && !artifact.getBaseVersion().equals(originalReactorVersions.get(versionlessArtifactKey))); if (isSnapshot) { return type + " - " + versionlessArtifactKey; } return null; }
/** Replies the version of the given plugin that is specified in the POM of the * plugin in which this mojo is located. * * @param groupId the identifier of the group. * @param artifactId thidentifier of the artifact. * @return the version, never <code>null</code> * @throws MojoExecutionException if the plugin was not found. */ public String getPluginDependencyVersion(String groupId, String artifactId) throws MojoExecutionException { final Map<String, Dependency> deps = getPluginDependencies(); final String key = ArtifactUtils.versionlessKey(groupId, artifactId); this.log.debug("COMPONENT DEPENDENCIES(getPluginVersionFromDependencies):"); //$NON-NLS-1$ this.log.debug(deps.toString()); final Dependency dep = deps.get(key); if (dep != null) { final String version = dep.getVersion(); if (version != null && !version.isEmpty()) { return version; } throw new MojoExecutionException(MessageFormat.format(Messages.MavenHelper_2, key)); } throw new MojoExecutionException(MessageFormat.format(Messages.MavenHelper_3, key, deps)); }
throw new DuplicateProjectException( projectId, conflictingProject.getFile(), project.getFile(), "Project '" + projectId + "' is duplicated in the reactor" ); String projectKey = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
private void validateProjects( List<MavenProject> projects ) { Map<String, MavenProject> projectsMap = new HashMap<>(); for ( MavenProject p : projects ) { String projectKey = ArtifactUtils.key( p.getGroupId(), p.getArtifactId(), p.getVersion() ); projectsMap.put( projectKey, p ); } for ( MavenProject project : projects ) { // MNG-1911 / MNG-5572: Building plugins with extensions cannot be part of reactor for ( Plugin plugin : project.getBuildPlugins() ) { if ( plugin.isExtensions() ) { String pluginKey = ArtifactUtils.key( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ); if ( projectsMap.containsKey( pluginKey ) ) { logger.warn( project.getName() + " uses " + plugin.getKey() + " as extensions, which is not possible within the same reactor build. " + "This plugin was pulled from the local repository!" ); } } } } }
/** * Append the systemPath of the referenced dependency to the buffer we're using * to build up the resolved command-line option. * @throws PathResolutionException * @throws ProjectBuildingException */ private String addDependencyPath( Matcher matcher, String src ) throws IOException, PathResolutionException { String groupId = matcher.group( 1 ); String artifactId = matcher.group( 2 ); String depKey = ArtifactUtils.versionlessKey( groupId, artifactId ); if ( artifactMap == null ) { artifactMap = ArtifactUtils.artifactMapByVersionlessId( artifacts ); } log.debug( "Artifact Map for Resolving @pathOf expressions:\n\n" + artifactMap.toString().replace( ',', '\n' ) ); Artifact artifact = (Artifact) artifactMap.get( depKey ); log.debug( "Resolving path for: " + artifact + " with key: " + depKey ); File path = pathResolver.resolve( artifact ); log.debug( "Artifact for key: " + depKey + " is: " + artifact ); log.debug( "Dependency path for artifact: " + artifact + " is: " + path ); return StringUtils.replace(src, matcher.group( 0 ), path.getCanonicalPath() ); }
private Set<String> getSnapshotDeps() { Set<String> snapshotDeps = new HashSet<>(); for (Artifact dep : project.getArtifacts()) { if (ArtifactUtils.isSnapshot(dep.getVersion())) { getLog().debug("SNAPSHOT dependency found: " + dep.toString()); snapshotDeps.add(dep.toString()); } } return snapshotDeps; }
private static String getProjectKey( MavenProject project ) { return ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ); }