Search in sources :

Example 6 with DefaultArtifactRepository

use of org.apache.maven.artifact.repository.DefaultArtifactRepository in project intellij-community by JetBrains.

the class Maven2ServerEmbedderImpl method retrieveAvailableVersions.

@NotNull
@Override
public List<String> retrieveAvailableVersions(@NotNull String groupId, @NotNull String artifactId, @NotNull List<MavenRemoteRepository> remoteRepositories) throws RemoteException {
    try {
        Artifact artifact = new DefaultArtifact(groupId, artifactId, VersionRange.createFromVersion(""), Artifact.SCOPE_COMPILE, "pom", null, new DefaultArtifactHandler("pom"));
        ArtifactRepositoryLayout repositoryLayout = getComponent(ArtifactRepositoryLayout.class);
        List versions = getComponent(ArtifactMetadataSource.class).retrieveAvailableVersions(artifact, new DefaultArtifactRepository("local", getLocalRepositoryFile().getPath(), repositoryLayout), convertRepositories(remoteRepositories));
        List<String> result = new ArrayList<String>();
        for (Object version : versions) {
            result.add(version.toString());
        }
        return result;
    } catch (Exception e) {
        Maven2ServerGlobals.getLogger().info(e);
    }
    return Collections.emptyList();
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) ArtifactMetadataSource(org.apache.maven.artifact.metadata.ArtifactMetadataSource) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) TimeoutException(java.util.concurrent.TimeoutException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ContextException(org.codehaus.plexus.context.ContextException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) ExecutionException(java.util.concurrent.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with DefaultArtifactRepository

use of org.apache.maven.artifact.repository.DefaultArtifactRepository in project intellij-community by JetBrains.

the class MavenEmbedder method createLocalRepository.

private ArtifactRepository createLocalRepository(MavenEmbedderSettings generalSettings) {
    ArtifactRepositoryLayout layout = getComponent(ArtifactRepositoryLayout.class, "default");
    ArtifactRepositoryFactory factory = getComponent(ArtifactRepositoryFactory.class);
    String url = mySettings.getLocalRepository();
    if (!url.startsWith("file:"))
        url = "file://" + url;
    ArtifactRepository localRepository = new DefaultArtifactRepository("local", url, layout);
    boolean snapshotPolicySet = mySettings.isOffline();
    if (!snapshotPolicySet && generalSettings.getSnapshotUpdatePolicy() == MavenEmbedderSettings.UpdatePolicy.ALWAYS_UPDATE) {
        factory.setGlobalUpdatePolicy(ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS);
    }
    factory.setGlobalChecksumPolicy(ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    return localRepository;
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) ArtifactRepositoryFactory(org.apache.maven.artifact.repository.ArtifactRepositoryFactory) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 8 with DefaultArtifactRepository

use of org.apache.maven.artifact.repository.DefaultArtifactRepository in project maven-plugins by apache.

the class BundlePackMojoTest method testPack_RemoveOne.

public void testPack_RemoveOne() throws Exception {
    File testPom = new File(getBasedir(), "src/test/resources/unit/bundle-pack/pom.xml");
    BundlePackMojo mojo = (BundlePackMojo) lookupMojo("bundle-pack", testPom);
    URL repoURL = new File(getBasedir(), "src/test/resources/repo").toURL();
    mojo.localRepository = new DefaultArtifactRepository("test", repoURL.toString(), new DefaultRepositoryLayout());
    // NOTE: This is sensitive to the lookupMojo method timing...
    TestInputHandler ih = (TestInputHandler) lookup(InputHandler.ROLE, "default");
    Stack<String> responses = new Stack<String>();
    responses.push("3");
    ih.setLineResponses(responses);
    File generatedFilesDir = new File(getBasedir(), "target/bundle-pack-tests");
    mojo.basedir = generatedFilesDir.getAbsolutePath();
    mojo.execute();
    File bundleSource = new File(generatedFilesDir, "testartifact-1.0-bundle.jar");
    Set<String> entryNames = new HashSet<String>();
    entryNames.add("testartifact-1.0-javadoc.jar");
    entryNames.add("testartifact-1.0.jar");
    entryNames.add("pom.xml");
    entryNames.add("META-INF/MANIFEST.MF");
    entryNames.add("META-INF/");
    Set<String> bannedNames = new HashSet<String>();
    // determined experimentally, so this could change!
    bannedNames.add("testartifact-1.0-sources.jar");
    assertZipContents(entryNames, bannedNames, bundleSource);
}
Also used : DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) File(java.io.File) TestInputHandler(org.apache.maven.plugins.repository.testutil.TestInputHandler) URL(java.net.URL) Stack(java.util.Stack) HashSet(java.util.HashSet)

Example 9 with DefaultArtifactRepository

use of org.apache.maven.artifact.repository.DefaultArtifactRepository in project maven-plugins by apache.

the class BundlePackMojoTest method testPack_PomPackaging.

public void testPack_PomPackaging() throws Exception {
    File testPom = new File(getBasedir(), "src/test/resources/unit/bundle-pack-parent/pom.xml");
    BundlePackMojo mojo = (BundlePackMojo) lookupMojo("bundle-pack", testPom);
    URL repoURL = new File(getBasedir(), "src/test/resources/repo").toURL();
    mojo.localRepository = new DefaultArtifactRepository("test", repoURL.toString(), new DefaultRepositoryLayout());
    File generatedFilesDir = new File(getBasedir(), "target/bundle-pack-parent-tests");
    mojo.basedir = generatedFilesDir.getAbsolutePath();
    // NOTE: This is sensitive to the lookupMojo method timing...
    TestInputHandler ih = (TestInputHandler) lookup(InputHandler.ROLE, "default");
    Stack<String> responses = new Stack<String>();
    responses.push("http://foo/");
    responses.push("scm:svn:http://foo/");
    responses.push("2,3");
    responses.push("0");
    ih.setLineResponses(responses);
    mojo.execute();
    File bundleSource = new File(generatedFilesDir, "testparent-1.0-bundle.jar");
    Set<String> entryNames = new HashSet<String>();
    entryNames.add("pom.xml");
    entryNames.add("META-INF/MANIFEST.MF");
    entryNames.add("META-INF/");
    assertZipContents(entryNames, Assertions.EMPTY_ENTRY_NAMES, bundleSource);
}
Also used : DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) File(java.io.File) TestInputHandler(org.apache.maven.plugins.repository.testutil.TestInputHandler) URL(java.net.URL) Stack(java.util.Stack) HashSet(java.util.HashSet)

Example 10 with DefaultArtifactRepository

use of org.apache.maven.artifact.repository.DefaultArtifactRepository in project maven-plugins by apache.

the class BundlePackMojoTest method testPack_RemoveTwoWithSpace.

public void testPack_RemoveTwoWithSpace() throws Exception {
    File testPom = new File(getBasedir(), "src/test/resources/unit/bundle-pack/pom.xml");
    BundlePackMojo mojo = (BundlePackMojo) lookupMojo("bundle-pack", testPom);
    URL repoURL = new File(getBasedir(), "src/test/resources/repo").toURL();
    mojo.localRepository = new DefaultArtifactRepository("test", repoURL.toString(), new DefaultRepositoryLayout());
    // NOTE: This is sensitive to the lookupMojo method timing...
    TestInputHandler ih = (TestInputHandler) lookup(InputHandler.ROLE, "default");
    Stack<String> responses = new Stack<String>();
    responses.push("2, 3");
    ih.setLineResponses(responses);
    File generatedFilesDir = new File(getBasedir(), "target/bundle-pack-tests");
    mojo.basedir = generatedFilesDir.getAbsolutePath();
    mojo.execute();
    File bundleSource = new File(generatedFilesDir, "testartifact-1.0-bundle.jar");
    Set<String> entryNames = new HashSet<String>();
    entryNames.add("testartifact-1.0.jar");
    entryNames.add("pom.xml");
    entryNames.add("META-INF/MANIFEST.MF");
    entryNames.add("META-INF/");
    Set<String> bannedNames = new HashSet<String>();
    // determined experimentally, so this could change!
    bannedNames.add("testartifact-1.0-sources.jar");
    bannedNames.add("testartifact-1.0-javadoc.jar");
    assertZipContents(entryNames, bannedNames, bundleSource);
}
Also used : DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) File(java.io.File) TestInputHandler(org.apache.maven.plugins.repository.testutil.TestInputHandler) URL(java.net.URL) Stack(java.util.Stack) HashSet(java.util.HashSet)

Aggregations

DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)13 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)10 File (java.io.File)8 URL (java.net.URL)6 HashSet (java.util.HashSet)6 Stack (java.util.Stack)5 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)5 Artifact (org.apache.maven.artifact.Artifact)4 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)4 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)2 ArtifactRepositoryLayout (org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MavenProject (org.apache.maven.project.MavenProject)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 FileReader (java.io.FileReader)1 InvocationHandler (java.lang.reflect.InvocationHandler)1