use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class DeployMojoTest method testAltReleaseDeploymentRepository.
public void testAltReleaseDeploymentRepository() throws Exception {
DeployMojo mojo = spy(new DeployMojo());
ArtifactRepository repository = mock(ArtifactRepository.class);
when(mojo.createDeploymentArtifactRepository("altReleaseDeploymentRepository", "http://localhost")).thenReturn(repository);
project.setVersion("1.0");
ProjectDeployerRequest pdr = new ProjectDeployerRequest().setProject(project).setAltReleaseDeploymentRepository("altReleaseDeploymentRepository::http://localhost");
assertEquals(repository, mojo.getDeploymentRepository(pdr));
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class DoapMojo method writeReleases.
/**
* Write all DOAP releases.
*
* @param writer not null
* @param project the Maven project, not null
* @throws MojoExecutionException if any
* @see <a href="http://usefulinc.com/ns/doap#release">http://usefulinc.com/ns/doap#release</a>
* @see <a href="http://usefulinc.com/ns/doap#Version">http://usefulinc.com/ns/doap#Version</a>
*/
private void writeReleases(XMLWriter writer, MavenProject project) throws MojoExecutionException {
Artifact artifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging());
RepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
for (ArtifactRepository repo : remoteRepositories) {
if (repo.isBlacklisted()) {
continue;
}
if (repo.getSnapshots().isEnabled()) {
continue;
}
if (repo.getReleases().isEnabled()) {
try {
repositoryMetadataManager.resolveAlways(metadata, localRepository, repo);
break;
} catch (RepositoryMetadataResolutionException e) {
throw new MojoExecutionException(metadata.extendedToString() + " could not be retrieved from repositories due to an error: " + e.getMessage(), e);
}
}
}
if (metadata.getMetadata().getVersioning() == null) {
messages.getWarnMessages().add("No versioning was found for " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ". Ignored DOAP <release/> tag.");
return;
}
List<String> versions = metadata.getMetadata().getVersioning().getVersions();
// Recent releases in first
Collections.reverse(versions);
boolean addComment = false;
int i = 0;
for (String version : versions) {
if (!addComment) {
DoapUtil.writeComment(writer, "Project releases.");
addComment = true;
}
DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "release");
DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "Version");
DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "name");
if (version.equals(metadata.getMetadata().getVersioning().getRelease())) {
writer.writeText("Latest stable release");
} else {
writer.writeText(project.getName() + " - " + version);
}
// name
writer.endElement();
DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "revision", version);
// list all file release from all remote repos
for (ArtifactRepository repo : remoteRepositories) {
Artifact artifactRelease = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), version, null, project.getPackaging());
if (artifactRelease == null) {
continue;
}
String fileRelease = repo.getUrl() + "/" + repo.pathOf(artifactRelease);
try {
DoapUtil.fetchURL(settings, new URL(fileRelease));
} catch (IOException e) {
getLog().debug("IOException :" + e.getMessage());
continue;
}
DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "file-release", fileRelease);
Date releaseDate = null;
try {
releaseDate = REPOSITORY_DATE_FORMAT.parse(metadata.getMetadata().getVersioning().getLastUpdated());
} catch (ParseException e) {
getLog().error("Unable to parse date '" + metadata.getMetadata().getVersioning().getLastUpdated() + "'");
continue;
}
// See MDOAP-11
if (i == 0) {
DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "created", DOAP_DATE_FORMAT.format(releaseDate));
}
}
// Version
writer.endElement();
// release
writer.endElement();
i++;
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class RepositoryUtils method dependencyExistsInRepo.
/**
* @param repo not null
* @param artifact not null
* @return <code>true</code> if the artifact exists in the given repo, <code>false</code> otherwise or if
* the repo is blacklisted.
*/
public boolean dependencyExistsInRepo(ArtifactRepository repo, Artifact artifact) {
if (repo.isBlacklisted()) {
if (log.isDebugEnabled()) {
log.debug("The repo '" + repo.getId() + "' is black listed - Ignored it");
}
return false;
}
if (UNKNOWN_HOSTS.contains(repo.getUrl())) {
if (log.isDebugEnabled()) {
log.debug("The repo url '" + repo.getUrl() + "' is unknown - Ignored it");
}
return false;
}
repo = wagonManager.getMirrorRepository(repo);
String id = repo.getId();
Repository repository = new Repository(id, repo.getUrl());
Wagon wagon;
try {
wagon = wagonManager.getWagon(repository);
} catch (UnsupportedProtocolException e) {
logError("Unsupported protocol: '" + repo.getProtocol() + "'", e);
return false;
} catch (WagonConfigurationException e) {
logError("Unsupported protocol: '" + repo.getProtocol() + "'", e);
return false;
}
wagon.setTimeout(1000);
if (log.isDebugEnabled()) {
Debug debug = new Debug();
wagon.addSessionListener(debug);
wagon.addTransferListener(debug);
}
try {
// FIXME when upgrading to maven 3.x : this must be changed.
AuthenticationInfo auth = wagonManager.getAuthenticationInfo(repo.getId());
ProxyInfo proxyInfo = getProxyInfo();
if (proxyInfo != null) {
wagon.connect(repository, auth, proxyInfo);
} else {
wagon.connect(repository, auth);
}
return wagon.resourceExists(StringUtils.replace(getDependencyUrlFromRepository(artifact, repo), repo.getUrl(), ""));
} catch (ConnectionException e) {
logError("Unable to connect to: " + repo.getUrl(), e);
return false;
} catch (AuthenticationException e) {
logError("Unable to connect to: " + repo.getUrl(), e);
return false;
} catch (TransferFailedException e) {
if (e.getCause() instanceof UnknownHostException) {
log.error("Unknown host " + e.getCause().getMessage() + " - ignored it");
UNKNOWN_HOSTS.add(repo.getUrl());
} else {
logError("Unable to determine if resource " + artifact + " exists in " + repo.getUrl(), e);
}
return false;
} catch (AuthorizationException e) {
logError("Unable to connect to: " + repo.getUrl(), e);
return false;
} catch (AbstractMethodError e) {
log.error("Wagon " + wagon.getClass().getName() + " does not support the resourceExists method");
return false;
} finally {
try {
wagon.disconnect();
} catch (ConnectionException e) {
logError("Error disconnecting wagon - ignored", e);
}
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class DependenciesRenderer method printRepositories.
private void printRepositories(Map<String, ArtifactRepository> repoMap, List<String> repoUrlBlackListed) {
// i18n
String repoid = getI18nString("repo.locations.column.repoid");
String url = getI18nString("repo.locations.column.url");
String release = getI18nString("repo.locations.column.release");
String snapshot = getI18nString("repo.locations.column.snapshot");
String blacklisted = getI18nString("repo.locations.column.blacklisted");
String releaseEnabled = getI18nString("repo.locations.cell.release.enabled");
String releaseDisabled = getI18nString("repo.locations.cell.release.disabled");
String snapshotEnabled = getI18nString("repo.locations.cell.snapshot.enabled");
String snapshotDisabled = getI18nString("repo.locations.cell.snapshot.disabled");
String blacklistedEnabled = getI18nString("repo.locations.cell.blacklisted.enabled");
String blacklistedDisabled = getI18nString("repo.locations.cell.blacklisted.disabled");
// Table header
String[] tableHeader;
int[] justificationRepo;
if (repoUrlBlackListed.isEmpty()) {
tableHeader = new String[] { repoid, url, release, snapshot };
justificationRepo = new int[] { Sink.JUSTIFY_LEFT, Sink.JUSTIFY_LEFT, Sink.JUSTIFY_CENTER, Sink.JUSTIFY_CENTER };
} else {
tableHeader = new String[] { repoid, url, release, snapshot, blacklisted };
justificationRepo = new int[] { Sink.JUSTIFY_LEFT, Sink.JUSTIFY_LEFT, Sink.JUSTIFY_CENTER, Sink.JUSTIFY_CENTER, Sink.JUSTIFY_CENTER };
}
startTable(justificationRepo, false);
tableHeader(tableHeader);
for (ArtifactRepository repo : repoMap.values()) {
List<ArtifactRepository> mirroredRepos = getMirroredRepositories(repo);
sink.tableRow();
sink.tableCell();
boolean addLineBreak = false;
for (ArtifactRepository r : mirroredRepos) {
if (addLineBreak) {
sink.lineBreak();
}
addLineBreak = true;
sink.text(r.getId());
}
sink.tableCell_();
sink.tableCell();
addLineBreak = false;
for (ArtifactRepository r : mirroredRepos) {
if (addLineBreak) {
sink.lineBreak();
}
addLineBreak = true;
if (repo.isBlacklisted()) {
sink.text(r.getUrl());
} else {
sink.link(r.getUrl());
sink.text(r.getUrl());
sink.link_();
}
}
sink.tableCell_();
ArtifactRepositoryPolicy releasePolicy = repo.getReleases();
tableCell(releasePolicy.isEnabled() ? releaseEnabled : releaseDisabled);
ArtifactRepositoryPolicy snapshotPolicy = repo.getSnapshots();
tableCell(snapshotPolicy.isEnabled() ? snapshotEnabled : snapshotDisabled);
if (!repoUrlBlackListed.isEmpty()) {
tableCell(repoUrlBlackListed.contains(repo.getUrl()) ? blacklistedEnabled : blacklistedDisabled);
}
sink.tableRow_();
}
endTable();
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class DependenciesRenderer method printArtifactsLocations.
private void printArtifactsLocations(Map<String, ArtifactRepository> repoMap, List<String> repoUrlBlackListed, List<Artifact> alldeps) {
// i18n
String artifact = getI18nString("repo.locations.column.artifact");
sink.paragraph();
sink.text(getI18nString("repo.locations.artifact.breakdown"));
sink.paragraph_();
List<String> repoIdList = new ArrayList<String>();
// removed blacklisted repo
for (Map.Entry<String, ArtifactRepository> entry : repoMap.entrySet()) {
String repokey = entry.getKey();
ArtifactRepository repo = entry.getValue();
if (!(repo.isBlacklisted() || repoUrlBlackListed.contains(repo.getUrl()))) {
repoIdList.add(repokey);
}
}
String[] tableHeader = new String[repoIdList.size() + 1];
int[] justificationRepo = new int[repoIdList.size() + 1];
tableHeader[0] = artifact;
justificationRepo[0] = Sink.JUSTIFY_LEFT;
int idnum = 1;
for (String id : repoIdList) {
tableHeader[idnum] = id;
justificationRepo[idnum] = Sink.JUSTIFY_CENTER;
idnum++;
}
Map<String, Integer> totalByRepo = new HashMap<String, Integer>();
TotalCell totaldeps = new TotalCell(DEFAULT_DECIMAL_FORMAT);
startTable(justificationRepo, false);
tableHeader(tableHeader);
for (Artifact dependency : alldeps) {
totaldeps.incrementTotal(dependency.getScope());
sink.tableRow();
tableCell(dependency.getId());
if (Artifact.SCOPE_SYSTEM.equals(dependency.getScope())) {
for (@SuppressWarnings("unused") String repoId : repoIdList) {
tableCell("-");
}
} else {
for (String repokey : repoIdList) {
ArtifactRepository repo = repoMap.get(repokey);
String depUrl = repoUtils.getDependencyUrlFromRepository(dependency, repo);
Integer old = totalByRepo.get(repokey);
if (old == null) {
old = 0;
totalByRepo.put(repokey, old);
}
boolean dependencyExists = false;
// check snapshots in snapshots repository only and releases in release repositories...
if ((dependency.isSnapshot() && repo.getSnapshots().isEnabled()) || (!dependency.isSnapshot() && repo.getReleases().isEnabled())) {
dependencyExists = repoUtils.dependencyExistsInRepo(repo, dependency);
}
if (dependencyExists) {
sink.tableCell();
if (StringUtils.isNotEmpty(depUrl)) {
sink.link(depUrl);
} else {
sink.text(depUrl);
}
sink.figure();
sink.figureCaption();
// TODO Translate me!
sink.text("Found at " + repo.getUrl());
sink.figureCaption_();
sink.figureGraphics("images/icon_success_sml.gif");
sink.figure_();
sink.link_();
sink.tableCell_();
totalByRepo.put(repokey, old.intValue() + 1);
} else {
tableCell("-");
}
}
}
sink.tableRow_();
}
// Total row
// reused key
tableHeader[0] = getI18nString("file.details.total");
tableHeader(tableHeader);
String[] totalRow = new String[repoIdList.size() + 1];
totalRow[0] = totaldeps.toString();
idnum = 1;
for (String repokey : repoIdList) {
Integer deps = totalByRepo.get(repokey);
totalRow[idnum++] = deps != null ? deps.toString() : "0";
}
tableRow(totalRow);
endTable();
}
Aggregations