public static Dependency cloneDependency( Dependency src ) { Dependency result = null; if ( src != null ) { result = new Dependency(); result.setArtifactId( src.getArtifactId() ); result.setClassifier( src.getClassifier() ); result.setExclusions( cloneList( src.getExclusions(), DEPENDENCY_EXCLUSION_CLONER ) ); result.setGroupId( src.getGroupId() ); result.setOptional( src.isOptional() ); result.setScope( src.getScope() ); result.setSystemPath( src.getSystemPath() ); result.setType( src.getType() ); result.setVersion( src.getVersion() ); } return result; }
protected void mergeDependency_Version( Dependency target, Dependency source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getVersion(); if ( src != null ) { if ( sourceDominant || target.getVersion() == null ) { target.setVersion( src ); target.setLocation( "version", source.getLocation( "version" ) ); } } }
protected void mergeDependency_GroupId( Dependency target, Dependency source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getGroupId(); if ( src != null ) { if ( sourceDominant || target.getGroupId() == null ) { target.setGroupId( src ); target.setLocation( "groupId", source.getLocation( "groupId" ) ); } } }
protected void mergeDependency_ArtifactId( Dependency target, Dependency source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getArtifactId(); if ( src != null ) { if ( sourceDominant || target.getArtifactId() == null ) { target.setArtifactId( src ); target.setLocation( "artifactId", source.getLocation( "artifactId" ) ); } } }
@Deprecated public List<Dependency> getTestDependencies() { Set<Artifact> artifacts = getArtifacts(); if ( ( artifacts == null ) || artifacts.isEmpty() ) { return Collections.emptyList(); } List<Dependency> list = new ArrayList<>( artifacts.size() ); for ( Artifact a : getArtifacts() ) { Dependency dependency = new Dependency(); dependency.setArtifactId( a.getArtifactId() ); dependency.setGroupId( a.getGroupId() ); dependency.setVersion( a.getVersion() ); dependency.setScope( a.getScope() ); dependency.setType( a.getType() ); dependency.setClassifier( a.getClassifier() ); list.add( dependency ); } return Collections.unmodifiableList( list ); }
getLog().info( "Ignoring reactor dependency: " + toString( dep ) ); continue; throw new MojoExecutionException( String.format( "Version %s is not available for artifact %s:%s", depVersion, artifact.getGroupId(), artifact.getArtifactId() ) ); String version = dep.getVersion(); if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, depVersion, getProject().getModel() ) ) getLog().info( "Updated " + toString( dep ) + " to version " + depVersion );
private Collection<Artifact> getAllDependencies() throws MojoExecutionException { List<Artifact> artifacts = new ArrayList<>(); for (Iterator<?> dependencies = project.getDependencies().iterator(); dependencies.hasNext();) { Dependency dependency = (Dependency)dependencies.next(); String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); versionRange = VersionRange.createFromVersionSpec(dependency.getVersion()); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException("unable to parse version", e); String type = dependency.getType(); if (type == null) { type = "jar"; String classifier = dependency.getClassifier(); boolean optional = dependency.isOptional(); String scope = dependency.getScope(); if (scope == null) { scope = Artifact.SCOPE_COMPILE; art.setFile(new File(dependency.getSystemPath())); for (Exclusion exclusion : dependency.getExclusions()) { exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId()); art.setDependencyFilter(newFilter);
/** * Determine the timestamp version of the snapshot dependency used in the build. * * @param dep * @return The timestamp version if exists, otherwise the original snapshot dependency version is returned. */ private String resolveSnapshotVersion( Dependency dep ) { getLog().debug( "Resolving snapshot version for dependency: " + dep ); String lockedVersion = dep.getVersion(); try { Artifact depArtifact = artifactFactory.createDependencyArtifact( dep.getGroupId(), dep.getArtifactId(), VersionRange.createFromVersionSpec( dep.getVersion() ), dep.getType(), dep.getClassifier(), dep.getScope() ); resolver.resolve( depArtifact, getProject().getRemoteArtifactRepositories(), localRepository ); lockedVersion = depArtifact.getVersion(); } catch ( Exception e ) { getLog().error( e ); } return lockedVersion; }
@Test public void getLocalArtifactUrl_shouldAddDependencyToDependenciesTask() { DependencyResolver dependencyResolver = createResolver(); DependencyJar dependencyJar = new DependencyJar("group1", "artifact1", "3", null); dependencyResolver.getLocalArtifactUrl(dependencyJar); List<Dependency> dependencies = dependenciesTask.getDependencies(); assertEquals(1, dependencies.size()); Dependency dependency = dependencies.get(0); assertEquals("group1", dependency.getGroupId()); assertEquals("artifact1", dependency.getArtifactId()); assertEquals("3", dependency.getVersion()); assertEquals("jar", dependency.getType()); assertNull(dependency.getClassifier()); }
private String determineVersion(ArtifactConfiguration artifact) throws MojoExecutionException { Optional<Artifact> resolvedDependency = project.getArtifacts() .stream() .filter( a -> { return Objects.equals( a.getGroupId(), artifact.getGroupId() ) && Objects.equals( a.getArtifactId(), artifact.getArtifactId() ) && Objects.equals( a.getClassifier(), artifact.getClassifier() ) && Objects.equals( a.getType(), artifact.getType() ); } ) if ( project.getDependencyManagement() != null ) { Optional<org.apache.maven.model.Dependency> managed = project.getDependencyManagement() .getDependencies() .stream() .filter( d -> { return Objects.equals( d.getGroupId(), artifact.getGroupId() ) && Objects.equals( d.getArtifactId(), artifact.getArtifactId() ) && Objects.equals( d.getClassifier(), artifact.getClassifier() ) && Objects.equals( d.getType(), artifact.getType() ); } ) .findFirst(); return managed.get().getVersion(); throw new MojoExecutionException( "A version must be given for artifact " + artifact.toDependencyString() + ". Either specify one explicitly, add it to the project dependencies" +
if (artifact.getArtifactId().equalsIgnoreCase("summer-onejar")) { artifact.updateVersion(artifact.getVersion(), localRepository); putEntry(out, new FileInputStream(artifact.getFile()), new ZipEntry(JAR_CLASSPATH + artifact.getFile().getName())); MavenProject project = mavenProjectBuilder.buildFromRepository(artifact, remoteArtifactRepositories, localRepository); List<Dependency> dependencies = project.getDependencies(); for (Dependency dependency : dependencies) { if (!"provided".equals(dependency.getScope())) { Artifact dependencyArtifact = artifactFactory.createArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType()); dependencyArtifact.updateVersion(dependencyArtifact.getVersion(), localRepository); putEntry(out, new FileInputStream(dependencyArtifact.getFile()), new ZipEntry(JAR_CLASSPATH + dependencyArtifact.getFile().getName())); getLog().error(e.getMessage(), e); throw new MojoExecutionException(e.getMessage(), e); } finally { IOUtils.closeQuietly(out);
protected Artifact resolveJRubyStdlibArtifact(Artifact jruby) throws DependencyResolutionRequiredException, MojoExecutionException { final ArtifactResolutionRequest request = new ArtifactResolutionRequest(); for (final Dependency artifact : this.project.getDependencies()) { if (artifact.getArtifactId().equals(JRUBY_STDLIB) // TODO this condition is not needed ? && !artifact.getScope().equals(Artifact.SCOPE_PROVIDED) && !artifact.getScope().equals(Artifact.SCOPE_SYSTEM)) { request.setArtifact(this.repositorySystem .createArtifact(artifact.getGroupId(), artifact .getArtifactId(), artifact.getVersion(), artifact.getType())); break; } } if (request.getArtifact() == null){ request.setResolveTransitively(true); request.setArtifact(jruby); } request.setLocalRepository(this.localRepository); request.setRemoteRepositories(this.project.getRemoteArtifactRepositories()); Set<Artifact> set = this.repositorySystem.resolve(request).getArtifacts(); for (Artifact a: set){ if (JRUBY_STDLIB.equals(a.getArtifactId())) { return a; } } throw new MojoExecutionException("failed to resolve jruby stdlib artifact"); }
generator.setResourceLocation(((Resource)project.getBuild().getResources().get( 0 )).getDirectory()); generator.setSchemaSourceDirectory(schemaSourceDirectory); getLog().error("Could not load class: " + complexBindingBaseClass); return; getLog().error("Could not load class: " + simpleBindingBaseClass); return; List l = project.getCompileClasspathElements(); for ( Iterator i = l.iterator(); i.hasNext(); ) { String element = (String) i.next(); List d = project.getDependencies(); if ( "jar".equals( dep.getType() ) ) { Artifact artifact = artifactFactory.createArtifact( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getScope(), dep.getType() ); Set artifacts = project.createArtifacts( artifactFactory, null, null); for ( Iterator a = artifacts.iterator(); a.hasNext(); ) { Artifact dartifact = (Artifact) a.next(); urls.add(dartifact.getFile().toURI().toURL()); getLog().error( e ); return;
generator.setResourceLocation(((Resource)project.getBuild().getResources().get( 0 )).getDirectory()); generator.setFollowComplexTypes(followComplexTypes); generator.setIncludes( includes ); for ( Iterator d = project.getDependencies().iterator(); d.hasNext(); ) { Dependency dep = (Dependency) d.next(); dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), null, dep.getType() ); try { artifactResolver.resolve( artifact, remoteRepositories, localRepository ); urls.add( artifact.getFile().toURI().toURL() ); getLog().error( "Unable to resolve " + artifact.getId() ); urls.add( new File(project.getBuild().getOutputDirectory()).toURI().toURL() ); getLog().error("Bad url: " + project.getBuild().getOutputDirectory() ); return; getLog().error("Could note load class: " + schemaClassName); return;
@Nonnull private MavenProject createProjectFromDependency(@Nonnull Dependency dependency) throws MojoExecutionException { String dependencyKey = dependency.toString(); if (mavenProjectByDependencyCache.containsKey(dependencyKey)) { return mavenProjectByDependencyCache.get(dependencyKey); } getLog().debug("createProjectFromDependency(" + dependency + ")"); Artifact artifactFromDependency = getArtifact(dependency); if (artifactFromDependency == null) { artifactFromDependency = new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType(), dependency.getClassifier(), artifactHandlerManager.getArtifactHandler(dependency.getType()) ); } ProjectBuildingRequest request = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest()); request.setRemoteRepositories(project.getRemoteArtifactRepositories()); // The artifacts are available repositories defined in the projects - this also covers configured mirrors. request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); request.setProcessPlugins(false); request.setResolveDependencies(false); try { ProjectBuildingResult result = projectBuilder.build(artifactFromDependency, request); MavenProject project = result.getProject(); mavenProjectByDependencyCache.put(dependencyKey, project); return project; } catch (ProjectBuildingException e) { throw new MojoExecutionException("Could not resolve required dependencies of POM dependency " + artifactFromDependency, e); } }
validateId( "dependencies.dependency.artifactId", result, d.getArtifactId() ); validateId( "dependencies.dependency.groupId", result, d.getGroupId() ); validateStringNotEmpty( "dependencies.dependency.type", result, d.getType(), d.getManagementKey() ); validateStringNotEmpty( "dependencies.dependency.version", result, d.getVersion(), d.getManagementKey() ); if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) ) String systemPath = d.getSystemPath(); else if ( StringUtils.isNotEmpty( d.getSystemPath() ) ) d.getArtifactId() ); d.getGroupId() ); if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) ) String systemPath = d.getSystemPath(); else if ( StringUtils.isNotEmpty( d.getSystemPath() ) ) else if ( Artifact.SCOPE_IMPORT.equals( d.getScope() ) ) if ( !"pom".equals( d.getType() ) ) else if ( d.getClassifier() != null )
private void createAppJson() throws MojoExecutionException { File appJsonFile = new File(project.getBuild().getTestOutputDirectory(), SenchaUtils.SENCHA_APP_FILENAME); getLog().info(String.format("Generating Sencha App %s for unit tests...", appJsonFile.getPath())); SenchaAppConfigBuilder configBuilder = new SenchaAppConfigBuilder(); try { configBuilder.destFile(appJsonFile); configBuilder.defaults(DEFAULT_TEST_APP_JSON); configBuilder.destFileComment("Auto-generated test application configuration. DO NOT EDIT!"); // require the package to test: configBuilder.require(getSenchaPackageName(project)); // add test scope dependencies: List<Dependency> projectDependencies = project.getDependencies(); for (Dependency dependency : projectDependencies) { if (isTestDependency(dependency)) { configBuilder.require(getSenchaPackageName(dependency.getGroupId(), dependency.getArtifactId())); } } configBuilder.buildFile(); } catch (IOException e) { throw new MojoExecutionException("Could not build test " + SenchaUtils.SENCHA_APP_FILENAME, e); } }
throw new DuplicateProjectException( projectId, conflictingProject.getFile(), project.getFile(), "Project '" + projectId + "' is duplicated in the reactor" ); String projectKey = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ); for ( Dependency dependency : project.getDependencies() ) addEdge( projectMap, vertexMap, project, projectVertex, dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), false, false ); Parent parent = project.getModel().getParent(); addEdge( projectMap, vertexMap, project, projectVertex, dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), false, true );
protected String findJenkinsVersion() throws MojoExecutionException { for(Dependency a : (List<Dependency>)project.getDependencies()) { boolean match; if (jenkinsCoreId!=null) match = (a.getGroupId()+':'+a.getArtifactId()).equals(jenkinsCoreId); else match = (a.getGroupId().equals("org.jenkins-ci.main") || a.getGroupId().equals("org.jvnet.hudson.main")) && (a.getArtifactId().equals("jenkins-core") || a.getArtifactId().equals("hudson-core")); if (match) { if (StringUtils.isNotBlank(jenkinsCoreVersionOverride)) { VersionNumber v1 = new VersionNumber(a.getVersion()); VersionNumber v2 = new VersionNumber(jenkinsCoreVersionOverride); if (v1.compareTo(v2) == -1) { return jenkinsCoreVersionOverride; } getLog().warn("Ignoring 'jenkinsCoreVersionOverride' of " + jenkinsCoreVersionOverride + " as the " + "autodetected version, " + a.getVersion() + ", is newer. Please remove the redundant " + "version override."); } return a.getVersion(); } } if (StringUtils.isNotBlank(jenkinsCoreVersionOverride)) { return jenkinsCoreVersionOverride; } throw new MojoExecutionException("Failed to determine Jenkins version this plugin depends on."); }
private void iterateThrough(List<Dependency> dependencies){ for(Dependency dep: dependencies){ getLog().info(" - dependency: " + dep.getGroupId() + "/" + dep.getArtifactId() + " " + dep.getVersion()); } }