use of org.apache.maven.artifact.repository.ArtifactRepository in project tycho by eclipse.
the class TychoMirrorSelectorTest method testWithPrefixMirror.
@Test
public void testWithPrefixMirror() {
ArtifactRepository repository = createArtifactRepository("neon-repo", "http://download.eclipse.org/eclipse/update/4.6");
Mirror prefixMatchingMirror1 = createMirror("myId1", "http://foo.bar", "http://download.eclipse.org");
Mirror prefixMatchingMirror2 = createMirror("myId2", "http://foo1.bar1", "http://abc.vxz");
Mirror selectedMirror = selector.getMirror(repository, Arrays.asList(prefixMatchingMirror1, prefixMatchingMirror2));
Assert.assertNotNull(selectedMirror);
Assert.assertEquals("http://foo.bar/eclipse/update/4.6", selectedMirror.getUrl());
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project tycho by eclipse.
the class TychoMirrorSelectorTest method createArtifactRepository.
private ArtifactRepository createArtifactRepository(String id, String url) {
ArtifactRepository repository = new MavenArtifactRepository();
repository.setId(id);
repository.setUrl(url);
repository.setLayout(new P2ArtifactRepositoryLayout());
return repository;
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project sts4 by spring-projects.
the class MavenBridge method addArtifactRepositories.
private void addArtifactRepositories(ArrayList<ArtifactRepository> artifactRepositories, List<Repository> repositories) throws MavenException {
for (Repository repository : repositories) {
try {
ArtifactRepository artifactRepository = lookup(RepositorySystem.class).buildArtifactRepository(repository);
artifactRepositories.add(artifactRepository);
} catch (InvalidRepositoryException ex) {
throw new MavenException(ex);
}
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project sts4 by spring-projects.
the class MavenBridge method setLastUpdated.
/* package */
void setLastUpdated(ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, Artifact artifact) throws MavenException {
Properties lastUpdated = loadLastUpdated(localRepository, artifact);
String timestamp = Long.toString(System.currentTimeMillis());
for (ArtifactRepository repository : remoteRepositories) {
lastUpdated.setProperty(getLastUpdatedKey(repository, artifact), timestamp);
}
File lastUpdatedFile = getLastUpdatedFile(localRepository, artifact);
try {
lastUpdatedFile.getParentFile().mkdirs();
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(lastUpdatedFile));
try {
lastUpdated.store(os, null);
} finally {
IOUtil.close(os);
}
} catch (IOException ex) {
throw new MavenException(ex);
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project sts4 by spring-projects.
the class MavenBridge method isUnavailable.
/**
* This is a temporary implementation that only works for artifacts resolved
* using #resolve.
*/
public boolean isUnavailable(String groupId, String artifactId, String version, String type, String classifier, List<ArtifactRepository> remoteRepositories) throws MavenException {
Artifact artifact = lookup(RepositorySystem.class).createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
ArtifactRepository localRepository = getLocalRepository();
File artifactFile = new File(localRepository.getBasedir(), localRepository.pathOf(artifact));
if (artifactFile.canRead()) {
// artifact is available locally
return false;
}
if (remoteRepositories == null || remoteRepositories.isEmpty()) {
// no remote repositories
return true;
}
// now is the hard part
Properties lastUpdated = loadLastUpdated(localRepository, artifact);
for (ArtifactRepository repository : remoteRepositories) {
String timestamp = lastUpdated.getProperty(getLastUpdatedKey(repository, artifact));
if (timestamp == null) {
// been checked yet
return false;
}
}
// been checked in the past
return true;
}
Aggregations