Search in sources :

Example 1 with DefaultRepositoryLayout

use of org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout 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 2 with DefaultRepositoryLayout

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

the class JiraUnicodeTestProjectStub method getRemoteArtifactRepositories.

/** {@inheritDoc} */
@Override
public List<ArtifactRepository> getRemoteArtifactRepositories() {
    ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE);
    ArtifactRepository repository = new MavenArtifactRepository("central", "http://repo1.maven.org/maven2", new DefaultRepositoryLayout(), policy, policy);
    return Collections.singletonList(repository);
}
Also used : ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository)

Example 3 with DefaultRepositoryLayout

use of org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout 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 DefaultRepositoryLayout

use of org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout 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 DefaultRepositoryLayout

use of org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout 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

DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)13 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)10 File (java.io.File)9 URL (java.net.URL)6 HashSet (java.util.HashSet)6 Stack (java.util.Stack)5 Artifact (org.apache.maven.artifact.Artifact)5 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)5 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)4 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)2 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 MavenProject (org.apache.maven.project.MavenProject)2 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1