Search in sources :

Example 81 with ArtifactRepository

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());
}
Also used : ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) Mirror(org.apache.maven.settings.Mirror) Test(org.junit.Test)

Example 82 with ArtifactRepository

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;
}
Also used : P2ArtifactRepositoryLayout(org.eclipse.tycho.core.p2.P2ArtifactRepositoryLayout) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository)

Example 83 with ArtifactRepository

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);
        }
    }
}
Also used : RepositorySystem(org.apache.maven.repository.RepositorySystem) Repository(org.apache.maven.model.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 84 with ArtifactRepository

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);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 85 with ArtifactRepository

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;
}
Also used : RepositorySystem(org.apache.maven.repository.RepositorySystem) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Properties(java.util.Properties) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)108 File (java.io.File)46 Artifact (org.apache.maven.artifact.Artifact)26 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)26 ArrayList (java.util.ArrayList)23 MavenProject (org.apache.maven.project.MavenProject)20 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)17 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 IOException (java.io.IOException)13 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)13 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)11 Properties (java.util.Properties)10 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)9 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)9 Model (org.apache.maven.model.Model)9 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)8 MojoFailureException (org.apache.maven.plugin.MojoFailureException)8 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)8 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)8 MavenProjectResourcesStub (org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub)7