Search in sources :

Example 6 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project sling by apache.

the class ArchetypeParametersWizardPage method initialize.

@SuppressWarnings("unchecked")
private void initialize() {
    if (propertiesTable == null) {
        return;
    }
    Archetype archetype = parent.getChooseArchetypePage().getSelectedArchetype();
    if (archetype == null) {
        return;
    }
    try {
        ArchetypeManager archetypeManager = MavenPluginActivator.getDefault().getArchetypeManager();
        ArtifactRepository remoteArchetypeRepository = archetypeManager.getArchetypeRepository(archetype);
        properties = (List<RequiredProperty>) archetypeManager.getRequiredProperties(archetype, remoteArchetypeRepository, null);
        Table table = propertiesViewer.getTable();
        table.setItemCount(properties.size());
        int i = 0;
        for (Iterator<RequiredProperty> it = properties.iterator(); it.hasNext(); ) {
            RequiredProperty rp = it.next();
            TableItem item = table.getItem(i++);
            if (!rp.getKey().equals(item.getText())) {
                // then create it - otherwise, reuse it
                item.setText(0, rp.getKey());
                item.setText(1, "");
                item.setData(item);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not process archetype: " + e.getMessage(), e);
    }
}
Also used : ArchetypeManager(org.eclipse.m2e.core.internal.archetype.ArchetypeManager) Table(org.eclipse.swt.widgets.Table) Archetype(org.apache.maven.archetype.catalog.Archetype) RequiredProperty(org.apache.maven.archetype.metadata.RequiredProperty) TableItem(org.eclipse.swt.widgets.TableItem) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 7 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project bnd by bndtools.

the class IndexerMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        logger.debug("skip project as configured");
        return;
    }
    if (scopes == null || scopes.isEmpty()) {
        scopes = Arrays.asList("compile", "runtime");
    }
    logger.debug("Indexing dependencies with scopes: {}", scopes);
    logger.debug("Including Transitive dependencies: {}", includeTransitive);
    logger.debug("Local file URLs permitted: {}", localURLs);
    logger.debug("Adding mvn: URLs as alternative content: {}", addMvnURLs);
    DependencyResolver dependencyResolver = new DependencyResolver(project, session, resolver, system, scopes, includeTransitive, new RemotePostProcessor(session, system, metadataReader, localURLs));
    Map<File, ArtifactResult> dependencies = dependencyResolver.resolve();
    Map<String, ArtifactRepository> repositories = new HashMap<>();
    for (ArtifactRepository artifactRepository : project.getRemoteArtifactRepositories()) {
        logger.debug("Located an artifact repository {}", artifactRepository.getId());
        repositories.put(artifactRepository.getId(), artifactRepository);
    }
    ArtifactRepository deploymentRepo = project.getDistributionManagementArtifactRepository();
    if (deploymentRepo != null) {
        logger.debug("Located a deployment repository {}", deploymentRepo.getId());
        if (repositories.get(deploymentRepo.getId()) == null) {
            repositories.put(deploymentRepo.getId(), deploymentRepo);
        } else {
            logger.info("The configured deployment repository {} has the same id as one of the remote artifact repositories. It is assumed that these repositories are the same.", deploymentRepo.getId());
        }
    }
    RepositoryURLResolver repositoryURLResolver = new RepositoryURLResolver(repositories);
    MavenURLResolver mavenURLResolver = new MavenURLResolver();
    ResourcesRepository resourcesRepository = new ResourcesRepository();
    XMLResourceGenerator xmlResourceGenerator = new XMLResourceGenerator();
    logger.debug("Indexing artifacts: {}", dependencies.keySet());
    try {
        IO.mkdirs(outputFile.getParentFile());
        for (Entry<File, ArtifactResult> entry : dependencies.entrySet()) {
            File file = entry.getKey();
            ResourceBuilder resourceBuilder = new ResourceBuilder();
            resourceBuilder.addFile(entry.getKey(), repositoryURLResolver.resolver(file, entry.getValue()));
            if (addMvnURLs) {
                CapabilityBuilder c = new CapabilityBuilder(ContentNamespace.CONTENT_NAMESPACE);
                c.addAttribute(ContentNamespace.CONTENT_NAMESPACE, SHA256.digest(file).asHex());
                c.addAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, mavenURLResolver.resolver(file, entry.getValue()));
                c.addAttribute(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE, file.length());
                c.addAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE, MavenURLResolver.MIME);
                resourceBuilder.addCapability(c);
            }
            resourcesRepository.add(resourceBuilder.build());
        }
        if (includeJar && project.getPackaging().equals("jar")) {
            File current = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".jar");
            if (current.exists()) {
                ResourceBuilder resourceBuilder = new ResourceBuilder();
                resourceBuilder.addFile(current, current.toURI());
                resourcesRepository.add(resourceBuilder.build());
            }
        }
        xmlResourceGenerator.repository(resourcesRepository).save(outputFile);
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    if (fail) {
        throw new MojoExecutionException("One or more URI lookups failed");
    }
    attach(outputFile, "osgi-index", "xml");
    if (includeGzip) {
        File gzipOutputFile = new File(outputFile.getPath() + ".gz");
        try {
            xmlResourceGenerator.save(gzipOutputFile);
        } catch (Exception e) {
            throw new MojoExecutionException("Unable to create the gzipped output file");
        }
        attach(gzipOutputFile, "osgi-index", "xml.gz");
    }
}
Also used : RemotePostProcessor(aQute.bnd.maven.lib.resolve.RemotePostProcessor) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DependencyResolver(aQute.bnd.maven.lib.resolve.DependencyResolver) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) XMLResourceGenerator(aQute.bnd.osgi.repository.XMLResourceGenerator) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 8 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository 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 repoDelimIndex = resourceLocation.indexOf('!');
        String repoUrl = resourceLocation.substring(0, repoDelimIndex);
        int paramIndex = repoUrl.indexOf("@");
        if (paramIndex >= 0) {
            repoUrl = repoUrl.substring(0, paramIndex);
        }
        repo = new DefaultArtifactRepository(repoUrl, repoUrl, new DefaultRepositoryLayout());
        org.apache.maven.repository.Proxy mavenProxy = configureProxyToInlineRepo();
        if (mavenProxy != null) {
            repo.setProxy(mavenProxy);
        }
        resourceLocation = resourceLocation.substring(repoDelimIndex + 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 9 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project fabric8 by jboss-fuse.

the class DeployToProfileMojo method addNeededRemoteRepository.

@SuppressWarnings("unchecked")
private void addNeededRemoteRepository() {
    // TODO: Remove this code when we use releases from Maven Central
    // included jboss-fs repo which is required until we use an Apache version of Karaf
    boolean found = false;
    if (remoteRepositories != null) {
        for (Object obj : remoteRepositories) {
            if (obj instanceof ArtifactRepository) {
                ArtifactRepository repo = (ArtifactRepository) obj;
                if (repo.getUrl().contains("repository.jboss.org/nexus/content/groups/fs-public")) {
                    found = true;
                    getLog().debug("Found existing (" + repo.getId() + ") remote repository: " + repo.getUrl());
                    break;
                }
            }
        }
    }
    if (!found) {
        ArtifactRepository fsPublic = new MavenArtifactRepository();
        fsPublic.setId("jboss-public-fs");
        fsPublic.setUrl("http://repository.jboss.org/nexus/content/groups/fs-public/");
        fsPublic.setLayout(new DefaultRepositoryLayout());
        fsPublic.setReleaseUpdatePolicy(new ArtifactRepositoryPolicy(true, "never", "warn"));
        fsPublic.setSnapshotUpdatePolicy(new ArtifactRepositoryPolicy(false, "never", "ignore"));
        if (remoteRepositories == null) {
            remoteRepositories = new ArrayList();
        }
        remoteRepositories.add(fsPublic);
        getLog().info("Adding needed remote repository: http://repository.jboss.org/nexus/content/groups/fs-public/");
    }
}
Also used : ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) ArrayList(java.util.ArrayList) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository)

Example 10 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project eclipse.jdt.ls by eclipse.

the class DependencyUtil method getLocalArtifactFile.

// From org.eclipse.m2e.jdt.internal.BuildPathManager#getAttachedArtifactFile
private static File getLocalArtifactFile(ArtifactKey a) {
    // can't use Maven resolve methods since they mark artifacts as not-found even if they could be resolved remotely
    IMaven maven = MavenPlugin.getMaven();
    try {
        ArtifactRepository localRepository = maven.getLocalRepository();
        String relPath = // $NON-NLS-1$
        maven.getArtifactPath(// $NON-NLS-1$
        localRepository, // $NON-NLS-1$
        a.getGroupId(), // $NON-NLS-1$
        a.getArtifactId(), // $NON-NLS-1$
        a.getVersion(), // $NON-NLS-1$
        "jar", a.getClassifier());
        File file = new File(localRepository.getBasedir(), relPath).getCanonicalFile();
        if (file.canRead() && file.isFile()) {
            return file;
        }
    } catch (CoreException | IOException ex) {
    // fall through
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) IOException(java.io.IOException) File(java.io.File) IMaven(org.eclipse.m2e.core.embedder.IMaven)

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