/** * For a given artifactItem with range this produces the list of artifactItems with available versions. * Versions are filtered based on configuration * Output file name is set as artifactId-version.type * @param artifactItemsWithRange * @return * @throws MojoExecutionException */ protected List<ArtifactItem> getProcessRangedArtifactItems(ArtifactItemsWithRange artifactItemsWithRange) throws MojoExecutionException { getLog().debug(logArtifactWithRange(artifactItemsWithRange)); List<DefaultArtifactVersion> avilableVersions = getAvailableVersions(artifactItemsWithRange); List<ArtifactItem> artifactItems = new ArrayList<ArtifactItem>(); for (DefaultArtifactVersion av : avilableVersions) { Artifact artifactWithVersion; if (StringUtils.isEmpty(artifactItemsWithRange.getClassifier())) { artifactWithVersion = factory.createDependencyArtifact( artifactItemsWithRange.getGroupId(), artifactItemsWithRange.getArtifactId(), VersionRange.createFromVersion(av.toString()), artifactItemsWithRange.getType(), null, Artifact.SCOPE_COMPILE ); } else { artifactWithVersion = factory.createDependencyArtifact( artifactItemsWithRange.getGroupId(), artifactItemsWithRange.getArtifactId(), VersionRange.createFromVersion(av.toString()), artifactItemsWithRange.getType(), artifactItemsWithRange.getClassifier(), Artifact.SCOPE_COMPILE ); } artifactWithVersion = resolveArtifact(artifactWithVersion); ArtifactItem artifactItem = new ArtifactItem(artifactWithVersion); //Destination name is artifactId-version.type artifactItem.setDestFileName(artifactItem.getArtifactId()+"-"+artifactItem.getVersion()+"."+artifactItem.getType()); //First preference goes to artifactItem output directory if(artifactItemsWithRange.getOutputDirectory() == null) { artifactItem.setOutputDirectory(outputDirectory); } else { artifactItem.setOutputDirectory(artifactItemsWithRange.getOutputDirectory()); } artifactItem.getOutputDirectory().mkdir(); artifactItem.setOverWrite(artifactItemsWithRange.getOverWrite()); artifactItem.setNeedsProcessing(true); getLog().info("Artifact : " + artifactItemsWithRange.getArtifactId() + " Found version : " + av.toString()); artifactItems.add(artifactItem); } return artifactItems; }
/** * Main work of copy range plugin starts here * @throws MojoExecutionException */ private void processArtifactItemsWithRange() throws MojoExecutionException { for (ArtifactItemsWithRange artifactItemsWithRange : artifactItems) { List<ArtifactItem> listOfArtifacts = getProcessRangedArtifactItems(artifactItemsWithRange); for (ArtifactItem artifactItem : listOfArtifacts ) { if (artifactItem.isNeedsProcessing()) { copyArtifact( artifactItem ); } else { this.getLog().info( artifactItem + " already exists in " + artifactItem.getOutputDirectory() ); } } } }
private Dependency asDependency(ArtifactItem item) { Dependency dep = new Dependency(); dep.setGroupId(item.getGroupId()); dep.setArtifactId(item.getArtifactId()); dep.setVersion(item.getVersion()); return dep; }
private ArtifactItem apiArtifactItem() { ArtifactItem item = new ArtifactItem(); item.setGroupId(apiArtifact.getGroupId() != null ? apiArtifact.getGroupId() : project.getGroupId()); item.setArtifactId(apiArtifact.getArtifactId() != null ? apiArtifact.getArtifactId() : apiArtifactId()); item.setVersion(apiArtifact.getVersion() != null ? apiArtifact.getVersion() : project.getVersion()); return item; }
private String asString(ArtifactItem item) { return item.getGroupId() + ":" + item.getArtifactId() + ":jar:" + item.getVersion(); }
private Element asElement(ArtifactItem item) { return element("artifactItem", // element("groupId", item.getGroupId()), // element("artifactId", item.getArtifactId()),// element("version", item.getVersion())); }
public void execute() throws MojoExecutionException { IvySettings settings = new IvySettings(); try { File settingsFile = new File(this.settings); if (settingsFile.exists()) { settings.load(settingsFile); } else { // maybe a URL? settings.load(new URL(this.settings)); } } catch (Exception e) { throw new MojoExecutionException("couldn't load ivy settings from '" + this.settings + "'", e); } Ivy ivy = Ivy.newInstance(settings); for (ArtifactItem item : dependencies) { // we need to resolve now to calculate the transitive // dependencies (if required) Set<Artifact> allResolved = resolve( ivy, item.getGroupId(), item.getArtifactId(), item.getVersion(), item.getClassifier(), item.getType(), transitive, item.getBaseVersion()); for (Artifact resolved : allResolved) { Dependency dep = new Dependency(); dep.setGroupId(resolved.getGroupId()); dep.setArtifactId(resolved.getArtifactId()); dep.setScope(scope); dep.setClassifier(resolved.getClassifier()); dep.setOptional(false); dep.setType(resolved.getType()); dep.setVersion(resolved.getVersion()); project.getModel().addDependency(dep); } } // force a re-calc of the dependencies so maven picks up our new ones project.setDependencyArtifacts(null); ((DefaultRepositorySystem) repoSystem).setArtifactResolver(new IvyArtifactResolver(ivy, artifactResolver)); }
/** * Resolves the artifact from the repository and copies it to the specified location. * * @param artifactItem containing the information about the Artifact to copy. * @throws MojoExecutionException with a message if an error occurs. * @see DependencyUtil#copyFile(File, File, Log) * @see DependencyUtil#getFormattedFileName(Artifact, boolean) */ protected void copyArtifact( ArtifactItem artifactItem ) throws MojoExecutionException { File destFile = new File( artifactItem.getOutputDirectory(), artifactItem.getDestFileName() ); copyFile( artifactItem.getArtifact().getFile(), destFile ); }