Validates that specified {@link Artifact} is a file.
@param artifact
556716
private static Artifact validateArtifact(final Artifact artifact) {
        if (!artifact.getFile().isFile()) {
            throw new IllegalArgumentException("<"+artifact.getFile()+"> is not a file");
        }
        return artifact;
    }
1087046
@SuppressWarnings("rawtypes")
    public List<File> downloadArtifacts( List artifactsOrNotations ) throws NaetherException {
        
        List<Artifact> artifacts = new ArrayList<Artifact>();
        
        for ( Object artifactsOrNotation : artifactsOrNotations ) {
            if ( artifactsOrNotation != null ) {
                if ( artifactsOrNotation instanceof String ) {
                    artifacts.add( new DefaultArtifact( (String) artifactsOrNotation ) );
                } else if ( artifactsOrNotation instanceof Artifact ) {
                    artifacts.add( (Artifact)artifactsOrNotation );
                } else {
                    throw new NaetherException( "Only String notations or Artifact instances allowed. Found " + artifactsOrNotation.getClass() );
                }
            } else {
                log.warn( "Null found in list of artifacts to download" );
            }
        }
        
        List<File> files = new ArrayList<File>();
        
        for ( Artifact artifact : artifacts ) {
            
            log.debug( "Downloading {}", artifact );
            
            ArtifactRequest artifactRequest = new ArtifactRequest();
            artifactRequest.setArtifact( artifact );
            for ( RemoteRepository repo : this.getRemoteRepositories() ) {
                artifactRequest.addRepository( repo );
            }
    
            RepositoryClient repoClient = new RepositoryClient(this.getLocalRepoPath());
            
            ArtifactResult artifactResult = null;
            try {
                artifactResult = repoClient.resolveArtifact(artifactRequest );
            } catch (ArtifactResolutionException e) {
                throw new ResolveException(e);
            }
    
            Artifact downloadedArtifact = artifactResult.getArtifact();
            files.add( downloadedArtifact.getFile() );
        }
        
        return files;
    }
454814
public Set<Artifact> resolve(String groupId, String artifactId) throws MojoExecutionException {
		final ArtifactResolutionRequest request = new ArtifactResolutionRequest();
		request.setResolveRoot(true);
		request.setResolveTransitively(true);
		request.setLocalRepository(getSession().getLocalRepository());
		request.setRemoteRepositories(getSession().getCurrentProject().getRemoteArtifactRepositories());
		request.setOffline(getSession().isOffline());
		request.setForceUpdate(getSession().getRequest().isUpdateSnapshots());
		request.setServers(getSession().getRequest().getServers());
		request.setMirrors(getSession().getRequest().getMirrors());
		request.setProxies(getSession().getRequest().getProxies());
		request.setArtifact(createArtifact(groupId, artifactId));

		final ArtifactResolutionResult result = resolve(request);

		return result.getArtifacts();
	}
487669
@Override
    protected Artifact createArtifact(final ArtifactItem item) throws MojoExecutionException {
        assert item != null;
        
        if (item.getVersion() == null) {
            throw new MojoExecutionException("Unable to find artifact without version specified: " + item.getGroupId()
                + ":" + item.getArtifactId() + ":" + item.getVersion() + " in either project dependencies or in project dependencyManagement.");
        }
        
        // if version is a range get the highest available version
        if (item.getVersion().trim().startsWith("[") || item.getVersion().trim().startsWith("(") ) {
            try {
                item.setVersion(resolveVersionRange(item.getGroupId(), item.getArtifactId(), item.getType(), item.getVersion()));
            } catch (VersionRangeResolutionException e) {
                throw new MojoExecutionException("Could not get the highest version from the range: " + item.getVersion(), e);
            }
        }
        
        return resolveArtifactItem(item);
    }
948111
public void addArtifact(final Artifact artifact) {
        if (!artifacts.contains(artifact)) {
            if (promoted) {
                artifact.setPromoted(promoted);
            }

            artifacts.add(artifact);
        }
    }
1056880
protected void processContent(Content file) {
        // Handle metadata/special cases
        String lowerCaseFileName = file.name.toLowerCase();
        if (lowerCaseFileName.endsWith("pom.properties")) {
            // handle pom properties files
            InputStream is = new ByteArrayInputStream(file.bytes);
            Metadata md = Metadata.fromPomProperties(is);
            putMetadata(file.name, md);
        }

        // This is separate as we may or may not want to fingerprint
        // all files.
        if (RECURSIVE) {
            Artifact record = Processor.process(file.bytes, file.name, true);
            addContent(record, file.name);
        }
    }
1233275
private void checkNonCoreArtifactId(Model model) throws EnforcerRuleException
    {
        String artifactId = model.getArtifactId();
        for (String prefix : CORE_ARTIFACT_ID_PREFIXES) {
            if (artifactId.startsWith(prefix)) {
                throw new EnforcerRuleException("The [%s] artifact id prefix is reserved for XWiki Core Committers.");
            }
        }
    }
945536
public static ValidationResult isValidAddOn(Path file) {
		if (file == null || file.getNameCount() == 0) {
			return new ValidationResult(ValidationResult.Validity.INVALID_PATH);
		}

		if (!isAddOnFileName(file.getFileName().toString())) {
			return new ValidationResult(ValidationResult.Validity.INVALID_FILE_NAME);
		}

		if (!Files.isRegularFile(file) || !Files.isReadable(file)) {
			return new ValidationResult(ValidationResult.Validity.FILE_NOT_READABLE);
		}

		try (ZipFile zip = new ZipFile(file.toFile())) {
			ZipEntry manifest = zip.getEntry(MANIFEST_FILE_NAME);
			if (manifest == null) {
				return new ValidationResult(ValidationResult.Validity.MISSING_MANIFEST);
			}

			try (InputStream zis = zip.getInputStream(manifest)) {
				try {
					return new ValidationResult(new ZapAddOnXmlFile(zis));
				} catch (Exception e) {
					return new ValidationResult(ValidationResult.Validity.INVALID_MANIFEST, e);
				}
			}
		} catch (ZipException e) {
			return new ValidationResult(ValidationResult.Validity.UNREADABLE_ZIP_FILE, e);
		} catch (Exception e) {
			return new ValidationResult(ValidationResult.Validity.IO_ERROR_FILE, e);
		}
	}
743768
protected void downloadArtifactTo(URL artifactUrl, File pluginFile, IAsyncResultHandler<File> handler) {
        InputStream istream = null;
        OutputStream ostream = null;
        try {
            URLConnection connection = artifactUrl.openConnection();
            connection.connect();
            if (connection instanceof HttpURLConnection) {
                HttpURLConnection httpConnection = (HttpURLConnection) connection;
                if (httpConnection.getResponseCode() != 200) {
                    handler.handle(AsyncResultImpl.create(null));
                    return;
                }
            }
            istream = connection.getInputStream();
            ostream = new FileOutputStream(pluginFile);
            IOUtils.copy(istream, ostream);
            ostream.flush();
            handler.handle(AsyncResultImpl.create(pluginFile));
        } catch (Exception e) {
            handler.handle(AsyncResultImpl.<File>create(e));
        } finally {
            IOUtils.closeQuietly(istream);
            IOUtils.closeQuietly(ostream);
        }
    }
315638
protected final File createDirectoryArtifact(final File outputDirectory,
            final String artifact) {
        // Construct artifact path based on output directory
        String path = asPath(outputDirectory.getAbsolutePath(), artifact);
        final File ret = new File(path);
        if (!ret.isDirectory()) {
            // Fail if the directory artifact couldn't be created
            if (!ret.mkdir()) {
                error(DIRECTORY_CREATION_FAILED + ret);
                bail(ExitCode.BAD_OUTPUT_DIRECTORY);
            }
        }
        return ret;
    }
89252
@Override
    public List<String> findVersions(final Artifact artifact) {
        return Arrays.asList(new String[]{artifact.getVersion()});
    }
1211021
private void importResource(Node parentNode, InputStream file_in, String resourceType, ArtifactDescriptor artifact)
            throws RepositoryException
   {
      // Note that artifactBean been initialized within constructor
      // resourceType can be jar, pom, metadata

      String filename;
      if (resourceType.equals("metadata"))
      {
         filename = "maven-metadata.xml";
      }
      else
      {
         filename = String.format("%s-%s.%s", artifact.getArtifactId(), artifact.getVersionId(), resourceType);
      }

      OutputStream fout = null;
      File tmp_file = null;
      try
      {
         String tmpFilename = getUniqueFilename(filename);
         tmp_file = File.createTempFile(tmpFilename, null);
         fout = new FileOutputStream(tmp_file);
         IOUtils.copy(file_in, fout);
         fout.flush();
      }
      catch (FileNotFoundException e)
      {
         LOG.error("Cannot create .tmp file for storing artifact", e);
      }
      catch (IOException e)
      {
         LOG.error("IO exception on .tmp file for storing artifact", e);
      }
      finally
      {
         IOUtils.closeQuietly(file_in);
         IOUtils.closeQuietly(fout);
      }

      writePrimaryContent(parentNode, filename, resourceType, tmp_file);
      writeChecksum(parentNode, filename, tmp_file, "SHA1");

      try
      {
         // and collect all garbage : temporary files
         FileUtils.forceDelete(tmp_file);
      }
      catch (IOException e)
      {
         LOG.error("Cannot delete tmp file", e);
      }

   }
254414
public Project dependsOnArtifact(Artifact artifact)
    {
        Project project = new Project();
        project.setArtifact(artifact); 
        project.setInputVariablesName(inputVarName);
        return project;
    }
350982
private synchronized void addResolved( Artifact artifact )
    {
        String path =
            artifact.getGroupId().replace( '.', '/' ) + '/' + artifact.getArtifactId() + "/" + artifact.getVersion();
        Map<String, Artifact> artifactMapper = this.children.get( path );
        if ( artifactMapper == null )
        {
            artifactMapper = new HashMap<String, Artifact>();
            this.children.put( path, artifactMapper );
        }
        artifactMapper.put( artifact.getName(), artifact );
        addResolved( path );
    }
269250
public static void checkValidFile(final File file) {
        checkNotNull("file", file);
        if (!file.exists()) {
            throw new IllegalArgumentException("The file '" + file + "' does not exist!");
        }
        if (!file.isFile()) {
            throw new IllegalArgumentException("The name '" + file + "' is not a file!");
        }
    }
764843
function () {
      var doUniqueArtifactIdsCheck = function (artifactsIds) {
        var duplicateArtifactIds = [];
        artifactsIds.forEach(function (artifactId) {
          var artifactIdUnderTest = artifactId;

          function filterById (id) {
            return id === artifactIdUnderTest;
          }

          var arrayByUniqueArtifactIds = artifactsIds.filter(filterById);
          if (arrayByUniqueArtifactIds.length > 1 && duplicateArtifactIds.indexOf(artifactIdUnderTest) < 0) {
            duplicateArtifactIds.push(artifactIdUnderTest);
          }
        });
        duplicateArtifactIds.forEach(function (artifactId) {
          errors.push(
            'RuleViolation identified: WebPackage contains multiple artifacts with \'artifactId\'=\'' +
            artifactId + '\'');
        });
      };
      //
      var collectArtifactIds = function (next) {
        var artifactsIds = [];
        if (doc.artifacts) {
          Object.keys(doc.artifacts).forEach(function (artifactType) {
            doc.artifacts[ artifactType ].forEach(function (artifact) {
              artifactsIds.push(artifact.artifactId);
            });
          });
        }
        next(artifactsIds);
      };
      collectArtifactIds(doUniqueArtifactIdsCheck);
    }
779240
public static Artifact withArtifactId(String artifactId)
    {
        Artifact artifact = new Artifact();
        artifact.artifactId = new RegexParameterizedPatternParser(artifactId);
        return artifact;
    }