Search in sources :

Example 1 with DefaultArtifactRepository

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

the class Maven2ServerIndexFetcher method connect.

public void connect(String _ignoredContextId, String _ignoredUrl) throws IOException {
    final ArtifactRepository mirrorRepository = myWagonManager.getMirrorRepository(new DefaultArtifactRepository(myOriginalRepositoryId, myOriginalRepositoryUrl, null));
    String mirrorUrl = mirrorRepository.getUrl();
    String indexUrl = mirrorUrl + (mirrorUrl.endsWith("/") ? "" : "/") + ".index";
    Repository repository = new Repository(myOriginalRepositoryId, indexUrl);
    try {
        myWagon = myWagonManager.getWagon(repository);
        myWagon.addTransferListener(myListener);
        myWagon.connect(repository, myWagonManager.getAuthenticationInfo(mirrorRepository.getId()), myWagonManager.getProxy(mirrorRepository.getProtocol()));
    } catch (AuthenticationException e) {
        IOException newEx = new IOException("Authentication exception connecting to " + repository);
        newEx.initCause(e);
        throw newEx;
    } catch (WagonException e) {
        IOException newEx = new IOException("Wagon exception connecting to " + repository);
        newEx.initCause(e);
        throw newEx;
    }
}
Also used : DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) Repository(org.apache.maven.wagon.repository.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) IOException(java.io.IOException) WagonException(org.apache.maven.wagon.WagonException)

Example 2 with DefaultArtifactRepository

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

the class MojoSupport method resourceToArtifact.

/**
     * Convert a feature resourceLocation (bundle or configuration file) into an artifact.
     *
     * @param resourceLocation The feature resource location (bundle or configuration file).
     * @param skipNonMavenProtocols A flag to skip protocol different than mvn:
     * @return The artifact corresponding to the resource.
     * @throws MojoExecutionException If the plugin execution fails.
     */
protected Artifact resourceToArtifact(String resourceLocation, boolean skipNonMavenProtocols) throws MojoExecutionException {
    resourceLocation = resourceLocation.replace("\r\n", "").replace("\n", "").replace(" ", "").replace("\t", "");
    final int index = resourceLocation.indexOf("mvn:");
    if (index < 0) {
        if (skipNonMavenProtocols) {
            return null;
        }
        throw new MojoExecutionException("Resource URL is not a Maven URL: " + resourceLocation);
    } else {
        resourceLocation = resourceLocation.substring(index + "mvn:".length());
    }
    // Truncate the URL when a '#', a '?' or a '$' is encountered
    final int index1 = resourceLocation.indexOf('?');
    final int index2 = resourceLocation.indexOf('#');
    int endIndex = -1;
    if (index1 > 0) {
        if (index2 > 0) {
            endIndex = Math.min(index1, index2);
        } else {
            endIndex = index1;
        }
    } else if (index2 > 0) {
        endIndex = index2;
    }
    if (endIndex >= 0) {
        resourceLocation = resourceLocation.substring(0, endIndex);
    }
    final int index3 = resourceLocation.indexOf('$');
    if (index3 > 0) {
        resourceLocation = resourceLocation.substring(0, index3);
    }
    //check if the resourceLocation descriptor contains also remote repository information.
    ArtifactRepository repo = null;
    if (resourceLocation.startsWith("http://")) {
        final int repoDelimIntex = resourceLocation.indexOf('!');
        String repoUrl = resourceLocation.substring(0, repoDelimIntex);
        repo = new DefaultArtifactRepository(repoUrl, repoUrl, new DefaultRepositoryLayout());
        org.apache.maven.repository.Proxy mavenProxy = configureProxyToInlineRepo();
        if (mavenProxy != null) {
            repo.setProxy(mavenProxy);
        }
        resourceLocation = resourceLocation.substring(repoDelimIntex + 1);
    }
    String[] parts = resourceLocation.split("/");
    String groupId = parts[0];
    String artifactId = parts[1];
    String version = null;
    String classifier = null;
    String type = "jar";
    if (parts.length > 2) {
        version = parts[2];
        if (parts.length > 3) {
            type = parts[3];
            if (parts.length > 4) {
                classifier = parts[4];
            }
        }
    } else {
        Dependency dep = findDependency(project.getDependencies(), artifactId, groupId);
        if (dep == null && project.getDependencyManagement() != null) {
            dep = findDependency(project.getDependencyManagement().getDependencies(), artifactId, groupId);
        }
        if (dep != null) {
            version = dep.getVersion();
            classifier = dep.getClassifier();
            type = dep.getType();
        }
    }
    if (version == null || version.isEmpty()) {
        throw new MojoExecutionException("Cannot find version for: " + resourceLocation);
    }
    Artifact artifact = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
    artifact.setRepository(repo);
    return artifact;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) Dependency(org.apache.maven.model.Dependency) Artifact(org.apache.maven.artifact.Artifact)

Example 3 with DefaultArtifactRepository

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

the class BundlePackMojoTest method testPack_RemoveTwo.

public void testPack_RemoveTwo() 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)

Example 4 with DefaultArtifactRepository

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

the class BundlePackMojoTest method testPack.

public void testPack() 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());
    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-sources.jar");
    entryNames.add("testartifact-1.0.jar");
    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) URL(java.net.URL) HashSet(java.util.HashSet)

Example 5 with DefaultArtifactRepository

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

the class BundlePackMojoTest method testPack_RemoveTwoUnordered.

public void testPack_RemoveTwoUnordered() 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,2");
    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