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(); Artifact artifact = artifactFactory.createArtifact( 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;
protected XSDSchema schema() { getLog().info( artifactFactory.toString() ); getLog().error( schemaSourceDirectory.getAbsolutePath() + " does not exist" ); return null; getLog().error( "Could not locate schema: " + schemaLocation.getName() ); return null; artifactFactory.createArtifact( "org.geotools", "gt2-xml-gml3", "2.7-SNAPSHOT", "compile", "jar" artifactFactory.createArtifact( "org.geotools", "gt2-xml-filter", "2.7-SNAPSHOT", "compile", "jar" getLog().debug("Attempting to dynamically resolve: " + artifact); try { Set resolvedArtifacts = project.createArtifacts( artifactFactory, null, null); ArtifactResolutionResult result = artifactResolver.resolveTransitively(resolvedArtifacts, artifact, remoteRepositories, localRepository, artifactMetadataSource); resolvedArtifacts = result.getArtifacts(); urls.add( resolvedArtifact.getFile().toURI().toURL() ); getLog().warn( "Unable to resolve " + artifact.getId(), e );
if ( !projectArtifact.isSnapshot() && ( status.compareTo( ArtifactStatus.DEPLOYED ) < 0 ) ) projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" ); try projectArtifact.setResolved( false ); artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories, localRepository );
try { if (outputFile==null) outputFile = new File(getProject().getBasedir(),"target/"+getProject().getArtifactId()+".war"); File war = getJenkinsWarArtifact().getFile(); rezip.addZipfileset(z); getProject().setArtifacts(resolveDependencies(dependencyResolution)); .map(a -> { getLog().debug("This plugin " + a + "to be added to custom war"); return projectArtifacts; // have to return someting from multiline lambda inside map() }); Artifact hpi = artifactFactory.createArtifact(a.getGroupId(),a.getArtifactId(),a.getVersion(),null,"hpi"); artifactResolver.resolve(hpi,getProject().getRemoteArtifactRepositories(), localRepository); if (hpi.getFile().isDirectory()) throw new UnsupportedOperationException(hpi.getFile()+" is a directory and not packaged yet. this isn't supported"); getLog().info("Generated "+outputFile); throw new MojoExecutionException("Failed to package war",e); } catch (AbstractArtifactResolutionException e) { throw new MojoExecutionException("Failed to package war",e);
final Artifact currentArtifact = validateArtifact(project.getArtifact()); final Version current = Version.parse(currentArtifact.getVersion()); try { final ArtifactRepository localRepository = (ArtifactRepository) helper.evaluate("${localRepository}"); helper.getLog().info("Version specified as <"+version+">"); } else { final ArtifactMetadataSource artifactMetadataSource = (ArtifactMetadataSource) helper.getComponent(ArtifactMetadataSource.class); final List<ArtifactVersion> availablePreviousVersions = filterNonPreviousVersions(availableVersions, current); if (availablePreviousVersions.isEmpty()) { helper.getLog().warn("No previously released version. Backward compatibility check not performed."); return; previousArtifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), version, null, project.getArtifact().getType()); final ArtifactResolver resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class ); resolver.resolve(previousArtifact, project.getRemoteArtifactRepositories(), localRepository); validateArtifact(previousArtifact); } catch (Exception e) { final Version previous = Version.parse(previousArtifact.getVersion()); final File previousJar = previousArtifact.getFile(); final File currentJar = currentArtifact.getFile();
private void updateMavenLib( Artifact artifact ) throws MojoExecutionException { try { File mavenLibDir = new File( System.getProperty( "maven.home" ), "lib/ext" ); artifactResolver.resolve( artifact, remoteRepositories, localRepository ); this.getLog().info( "Copy " + artifact.getFile() + " to " + mavenLibDir ); FileUtils.copyFileToDirectory( artifact.getFile(), mavenLibDir ); } catch ( Exception e ) { throw new MojoExecutionException( "Unable to download artifact", e ); } } }
private File getHarnessNbm() throws MojoExecutionException { @SuppressWarnings( "unchecked" ) Set<Artifact> artifacts = project.getArtifacts(); String version = null; for (Artifact a : artifacts) { if ("org.netbeans.modules".equals(a.getGroupId()) && "org-netbeans-bootstrap".equals(a.getArtifactId())) { version = a.getBaseVersion(); //base version in non-snapshot should equals version, in snapshots to X-SNAPSHOT, not timestamp break; } } if (version == null) { throw new MojoExecutionException( "We could not find org-netbeans-bootstrap among the modules in the application. Launchers could not be found."); } Artifact nbmArt = artifactFactory.createArtifact( "org.netbeans.modules", "org-netbeans-modules-apisupport-harness", version, "compile", "nbm-file"); try { artifactResolver.resolve( nbmArt, project.getRemoteArtifactRepositories(), localRepository ); } catch ( ArtifactResolutionException | ArtifactNotFoundException ex ) { throw new MojoExecutionException( "Failed to retrieve the nbm file from repository", ex ); } return nbmArt.getFile(); }
/** * Determine the timestamp version of the snapshot artifact used in the build. * * @param artifact * @return The timestamp version if exists, otherwise the original snapshot artifact version is returned. */ private String resolveSnapshotVersion( Artifact artifact ) { getLog().debug( "Resolving snapshot version for artifact: " + artifact ); String lockedVersion = artifact.getVersion(); try { resolver.resolve( artifact, getProject().getRemoteArtifactRepositories(), localRepository ); lockedVersion = artifact.getVersion(); } catch ( Exception e ) { getLog().error( e ); } return lockedVersion; }
protected List<File> getModulesJARs() throws MojoExecutionException { List<String> resolved = new ArrayList<String>(); List<File> result = new ArrayList<File>(); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setLocalRepository(session.getRequest().getLocalRepository()); // TODO: manage remote repositories request.setRemoteRepositories(session.getRequest().getRemoteRepositories()); //request.setRemoteRepositories(remoteRepositories); for (Object a : project.getDependencyArtifacts()) { // dependencyArtifacts contains modules from Maven reactor Artifact artifact = (Artifact) a; if (BW6Utils.isBW6(artifact)) { if (!"system".equals(artifact.getScope()) || artifact.getFile() == null || !artifact.getFile().exists()) { request.setArtifact(artifact); ArtifactResolutionResult r = resolver.resolve(request); if (r.isSuccess()) { getLog().debug("Successfully resolved artifact '" + artifact.getGroupId() + ":" + artifact.getArtifactId() + "'"); } if (artifact.getFile() == null || !artifact.getFile().exists()) { throw new MojoExecutionException(Messages.DEPENDENCY_RESOLUTION_FAILED, new FileNotFoundException()); } getLog().debug(artifact.getFile().getAbsolutePath()); } result.add(artifact.getFile()); resolved.add(artifact.getArtifactId()+"-"+artifact.getVersion().replace("-SNAPSHOT", ".qualifier")); } } return result; }
Artifact artifact=null; if( nativeSrcDependency==null ) { artifact = artifactFactory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), "zip", sourceClassifier); } else { artifact = artifactFactory.createArtifactWithClassifier(nativeSrcDependency.getGroupId(), nativeSrcDependency.getArtifactId(), nativeSrcDependency.getVersion(), nativeSrcDependency.getType(), nativeSrcDependency.getClassifier()); artifactResolver.resolveAlways(artifact, remoteArtifactRepositories, localRepository); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Error downloading.", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Requested download does not exist.", e); packageZipFile = artifact.getFile(); if( packageZipFile.isDirectory() ) { throw new MojoExecutionException("Add a '-Dnative-src-url=file:...' to have maven download the native package"); getLog().info("Extracting "+packageZipFile+" to "+dest);
private void installLibDependency(File libDir) throws Exception { ArtifactRepository artifactRepository = getArtifactRepository(libDir.getAbsolutePath()); getLog().info("Install tars artifact..."); Set<Artifact> projectDependency = project.getDependencyArtifacts(); Artifact tarsArtifact = null; for (Artifact artifact : projectDependency) { if (artifact.getArtifactId().contains("tars")) { getLog().info(String.format("Use tars artifact %s-%s-%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion())); tarsArtifact = artifact; break; tarsArtifact = artifactFactory.createArtifact(tarsGroupId, tarsArtifactId, tarsVersion, Artifact.SCOPE_COMPILE, "jar"); artifactResolver.resolve(tarsArtifact, remoteRepositories, localRepository); installArtifact(tarsArtifact, libDir, artifactRepository, useTimestampInSnapshotFileName); throw new MojoExecutionException("Unable to install tars artifact dependency."); artifactResolver.resolve(artifact, remoteRepositories, localRepository); } catch (final ArtifactResolutionException e) { throw new MojoExecutionException("Unable to resolve " + artifact, e); } catch (final ArtifactNotFoundException e) { throw new MojoExecutionException("Unable to resolve " + artifact, e);
factory.createDependencyArtifact( comparisonGroupId, comparisonArtifactId, range, Artifact.SCOPE_COMPILE ); if ( !previousArtifact.getVersionRange().isSelectedVersionKnown( previousArtifact ) ) getLog().debug( "Searching for versions in range: " + previousArtifact.getVersionRange() ); @SuppressWarnings( "unchecked" ) previousArtifact.selectVersion( version.toString() ); throw new MojoExecutionException( "Error determining previous version: " + amre.getMessage(), amre ); if ( previousArtifact.getVersion() == null ) getLog().info( "Unable to find a previous version of the project in the repository" ); return null; resolver.resolve( previousArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository() ); throw new MojoExecutionException( "Artifact " + previousArtifact + " cannot be resolved : " + are.getMessage(), are ); throw new MojoExecutionException( "Artifact " + previousArtifact + " does not exist on local/remote repositories", anfe );
getLog().debug( "Proposal is to update from " + currentVersion + " to " + updateVersion ); getLog().warn( "Not updating version: could not resolve any versions" ); return false; artifact.setVersion( updateVersion.toString() ); try resolver.resolveAlways( artifact, remoteArtifactRepositories, localRepository ); getLog().warn( "Not updating version: could not resolve " + artifact.toString(), e ); return false;
for (org.apache.maven.artifact.Artifact projectDependency : ((Set<org.apache.maven.artifact.Artifact>) this.project.getArtifacts())) { if (pathEntry.equals(projectDependency.getFile())) { if (skipSourceJarLookup(projectDependency)) { getLog().debug("Skipping the source lookup for " + projectDependency.toString() + "..."); getLog().debug("Attemping to lookup source artifact for " + projectDependency.toString() + "..."); try { org.apache.maven.artifact.Artifact sourceArtifact = this.artifactFactory.createArtifactWithClassifier(projectDependency.getGroupId(), projectDependency.getArtifactId(), projectDependency.getVersion(), projectDependency.getType(), "sources"); this.artifactResolver.resolve(sourceArtifact, this.project.getRemoteArtifactRepositories(), this.localRepository); String path = sourceArtifact.getFile().getAbsolutePath(); getLog().debug("Source artifact found at " + path + "."); sourceJar = path; break;
private Set<org.apache.maven.artifact.Artifact> getTransitiveDependency(org.apache.maven.artifact.Artifact artifact) throws MojoFailureException { try { org.apache.maven.artifact.Artifact pomArtifact = artifactFactory.createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact .getVersion(), artifact.getClassifier(), "pom"); MavenProject pomProject = mavenProjectBuilder.buildFromRepository(pomArtifact, this.remoteRepositories, this.localRepository); Set<org.apache.maven.artifact.Artifact> dependents = pomProject.createArtifacts(this.artifactFactory, null, null); ArtifactResolutionResult result = resolver.resolveTransitively(dependents, pomArtifact, this.localRepository, this.remoteRepositories, this.metadatSource, null); if (result != null) { getLog().debug("Found transitive dependency : " + result); return result.getArtifacts(); getLog().debug("Could not resolved the dependency", e); throw new MojoFailureException("Could not resolved the dependency : " + e.getMessage()); } catch (ArtifactNotFoundException e) { getLog().debug("Could not find the dependency", e); throw new MojoFailureException("Could not find the dependency : " + e.getMessage()); } catch (ProjectBuildingException e) {
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(); Set artifacts = project.createArtifacts( artifactFactory, null, null); ArtifactResolutionResult result = artifactResolver.resolveTransitively(artifacts, artifact, remoteRepositories, localRepository, artifactMetadataSource); artifacts = result.getArtifacts(); for ( Iterator a = artifacts.iterator(); a.hasNext(); ) { Artifact dartifact = (Artifact) a.next(); urls.add(dartifact.getFile().toURI().toURL()); getLog().error( e ); return;
throws ProjectBuildingException String projectId = safeVersionlessKey( artifact.getGroupId(), artifact.getArtifactId() ); if ( "pom".equals( artifact.getType() ) ) artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository ); File file = projectArtifact.getFile();
getLog().warn( "fail to create versionRange from version: " + additionalWebapp.getVersion(), e ); vr = VersionRange.createFromVersion( additionalWebapp.getVersion() ); factory.createDependencyArtifact( additionalWebapp.getGroupId(), additionalWebapp.getArtifactId(), vr, additionalWebapp.getType(), null, Artifact.SCOPE_COMPILE ); factory.createDependencyArtifact( additionalWebapp.getGroupId(), additionalWebapp.getArtifactId(), vr, additionalWebapp.getType(), additionalWebapp.getClassifier(), Artifact.SCOPE_COMPILE ); resolver.resolve( artifact, project.getRemoteArtifactRepositories(), this.local ); throw new MojoExecutionException( "Unable to resolve artifact.", e ); throw new MojoExecutionException( "Unable to find artifact.", e );
protected File getDependency(ArtifactDescription artifactDescription) throws MojoExecutionException, MojoFailureException { try { Artifact artifact = artifactFactory.createArtifact(artifactDescription.getGroupId(), artifactDescription.getArtifactId(), artifactDescription.getVersion(), null, artifactDescription.getType()); getLog().info("Resolving " + artifact); artifactResolver.resolve(artifact, mavenProject.getRemoteArtifactRepositories(), localRepository); return artifact.getFile(); } catch (AbstractArtifactResolutionException e) { throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e); } catch (Exception e) { throw new MojoFailureException("Couldn't download artifact: " + e.getMessage()); } }
/** * Execute the dependency calculator. * @return List of dependency files. * @throws Exception If anything goes wrong. */ public Set<File> execute() throws Exception { ProfileManager profileManager = new DefaultProfileManager(container); fixupProjectArtifact(); // Calculate the new deps Artifact art = mavenProject.getArtifact(); Artifact art2 = artifactFactory.createArtifactWithClassifier(art .getGroupId() + ".cargodeps", art.getArtifactId(), art.getVersion(), "pom", null); resolver.resolve(art2, remoteRepositories, localRepository); MavenProject mavenProject = mavenProjectBuilder.buildWithDependencies( art2.getFile(), localRepository, profileManager); Set<File> filesToAdd = new HashSet<File>(); for (Object artifact : mavenProject.getArtifacts()) { Artifact artdep = (Artifact) artifact; if (artdep.getType().equals("jar")) { resolver.resolve(artdep, remoteRepositories, localRepository); filesToAdd.add(artdep.getFile()); } } return filesToAdd; }