Example usage for org.apache.maven.artifact.repository ArtifactRepository getLayout

List of usage examples for org.apache.maven.artifact.repository ArtifactRepository getLayout

Introduction

In this page you can find the example usage for org.apache.maven.artifact.repository ArtifactRepository getLayout.

Prototype

ArtifactRepositoryLayout getLayout();

Source Link

Usage

From source file:com.rebaze.maven.support.AetherUtils.java

License:Open Source License

public static String getLayout(ArtifactRepository repo) {
    try {/*  w  w  w.j  av a 2s  . c  o m*/
        return repo.getLayout().getId();
    } catch (LinkageError e) {
        /*
         * NOTE: getId() was added in 3.x and is as such not implemented by plugins compiled against 2.x APIs.
         */
        String className = repo.getLayout().getClass().getSimpleName();
        if (className.endsWith("RepositoryLayout")) {
            String layout = className.substring(0, className.length() - "RepositoryLayout".length());
            if (layout.length() > 0) {
                layout = Character.toLowerCase(layout.charAt(0)) + layout.substring(1);
                return layout;
            }
        }
        return "";
    }
}

From source file:me.gladwell.eclipse.m2e.android.resolve.eclipse.EclipseAetherLibraryResolver.java

License:Open Source License

public List<Library> resolveLibraries(Dependency dependency, String type, MavenProject project) {
    final DefaultArtifact artifact = new DefaultArtifact(dependency.getGroup(), dependency.getName(), type,
            dependency.getVersion());/*from  w w w .ja va2  s.c  om*/

    final List<ArtifactRepository> repositories = project.getRemoteArtifactRepositories();
    final List<RemoteRepository> remoteRepositories = new ArrayList<RemoteRepository>();

    for (ArtifactRepository repository : repositories) {
        RemoteRepository repo = new RemoteRepository.Builder(repository.getId(),
                repository.getLayout().toString(), repository.getUrl()).build();
        remoteRepositories.add(repo);
    }

    return resolveDependencies(artifact, remoteRepositories);
}

From source file:me.gladwell.eclipse.m2e.android.resolve.sonatype.SonatypeAetherLibraryResolver.java

License:Open Source License

public List<Library> resolveLibraries(Dependency dependency, String type, MavenProject project) {
    final DefaultArtifact artifact = new DefaultArtifact(dependency.getGroup(), dependency.getName(), type,
            dependency.getVersion());//  w w  w  . ja va2  s .c o m

    final List<ArtifactRepository> repositories = project.getRemoteArtifactRepositories();
    final List<RemoteRepository> remoteRepositories = new ArrayList<RemoteRepository>();

    for (ArtifactRepository repository : repositories) {
        RemoteRepository repo = new RemoteRepository(repository.getId(), repository.getLayout().toString(),
                repository.getUrl());
        remoteRepositories.add(repo);
    }

    return resolveDependencies(artifact, remoteRepositories);
}

From source file:net.officefloor.launch.woof.WoofDevelopmentConfigurationLoader.java

License:Open Source License

/**
 * Obtains the GWT development class path to match POM configuration. In
 * particular to ensure same version of <code>gwt-dev</code> as the
 * <code>gwt-user</code> used.
 * // www .  j a  v a2s  .c o m
 * @param pomFile
 *            Maven POM file.
 * @return GWT development class path.
 * @throws Exception
 *             If fails to obtain the GWT development class path.
 */
public static String[] getDevModeClassPath(File pomFile) throws Exception {

    // Create initial class path factory
    ClassPathFactoryImpl initial = new ClassPathFactoryImpl(null, new RemoteRepository[0]);

    // Obtain the Maven project and its remote repositories
    MavenProject project = initial.getMavenProject(pomFile);
    List<RemoteRepository> remoteRepositories = new LinkedList<RemoteRepository>();
    for (ArtifactRepository repository : project.getRemoteArtifactRepositories()) {
        remoteRepositories.add(
                new RemoteRepository(repository.getId(), repository.getLayout().getId(), repository.getUrl()));
    }

    // Create class path factory from POM remote repositories
    ClassPathFactory factory = new ClassPathFactoryImpl(null,
            remoteRepositories.toArray(new RemoteRepository[remoteRepositories.size()]));

    // Keep track of class path
    List<String> gwtClassPath = new LinkedList<String>();

    // Obtain the GWT version
    String gwtDevVersion = null;
    for (Dependency dependency : project.getDependencies()) {
        String groupId = dependency.getGroupId();
        String artifactId = dependency.getArtifactId();
        if ((GWT_GROUP_ID.equals(groupId)) && (GWT_USER_ARTIFACT_ID.equals(artifactId))) {
            gwtDevVersion = dependency.getVersion();
        }
    }
    if (gwtDevVersion == null) {
        // Use default version of GWT
        gwtDevVersion = DEFAULT_GWT_DEV_VERSION;

        // Must include GWT User for running
        String[] userClassPath = factory.createArtifactClassPath(GWT_GROUP_ID, GWT_USER_ARTIFACT_ID,
                gwtDevVersion, null, null);
        gwtClassPath.addAll(Arrays.asList(userClassPath));
    }

    // Include the class path for gwt-dev
    String[] devClassPath = factory.createArtifactClassPath(GWT_GROUP_ID, GWT_DEV_ARTIFACT_ID, gwtDevVersion,
            null, null);
    for (String classPathEntry : devClassPath) {

        // Ignore if already included
        if (gwtClassPath.contains(classPathEntry)) {
            continue;
        }

        // Include class path
        gwtClassPath.add(classPathEntry);
    }

    // Return the GWT class path
    return gwtClassPath.toArray(new String[gwtClassPath.size()]);
}

From source file:net.officefloor.maven.StartOfficeBuildingGoal.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    // Ensure have configured values
    ensureNotNull("Must have project", this.project);
    ensureNotNull("Must have plug-in dependencies", this.pluginDependencies);
    ensureNotNull("Must have local repository", this.localRepository);
    ensureNotNull("Must have repository system", this.repositorySystem);
    ensureNotNull("Port not configured for the " + OfficeBuilding.class.getSimpleName(), this.port);

    // Indicate the configuration
    final Log log = this.getLog();
    log.debug(OfficeBuilding.class.getSimpleName() + " configuration:");
    log.debug("\tPort = " + this.port);

    // Create the environment properties
    Properties environment = new Properties();
    environment.putAll(this.project.getProperties());

    // Log the properties
    log.debug("\tProperties:");
    for (String propertyName : environment.stringPropertyNames()) {
        log.debug("\t\t" + propertyName + " = " + environment.getProperty(propertyName));
    }//w ww.java  2 s .c  o m

    // Obtain the plugin dependency inclusions
    List<Artifact> artifactInclusions = new ArrayList<Artifact>(this.pluginDependencies.size());
    for (PluginDependencyInclusion inclusion : this.dependencyInclusions) {

        // Must match on dependency for inclusion
        Artifact includedDependency = null;
        for (Artifact dependency : this.pluginDependencies) {
            if ((inclusion.groupId.equals(dependency.getGroupId()))
                    && (inclusion.artifactId.equals(dependency.getArtifactId()))
                    && (inclusion.type.equals(dependency.getType())) && ((inclusion.classifier == null)
                            || (inclusion.classifier.equals(dependency.getClassifier())))) {
                // Found the dependency to include
                includedDependency = dependency;
            }
        }

        // Ensure have dependency for inclusion
        if (includedDependency == null) {
            throw newMojoExecutionException("Failed to obtain plug-in dependency " + inclusion.groupId + ":"
                    + inclusion.artifactId + (inclusion.classifier == null ? "" : ":" + inclusion.classifier)
                    + ":" + inclusion.type, null);

        }

        // Include the dependency
        artifactInclusions.add(includedDependency);
    }

    // Obtain the class path for OfficeBuilding
    String classPath = null;
    try {

        // Indicate the remote repositories
        log.debug("\tRemote repositories:");

        // Obtain remote repositories and load to class path factory
        List<RemoteRepository> remoteRepositories = new LinkedList<RemoteRepository>();
        List<String> urls = new LinkedList<String>();
        for (Object object : this.project.getRemoteArtifactRepositories()) {
            ArtifactRepository repository = (ArtifactRepository) object;
            String remoteRepositoryUrl = repository.getUrl();
            remoteRepositories.add(new RemoteRepository(repository.getId(), repository.getLayout().getId(),
                    remoteRepositoryUrl));
            urls.add(remoteRepositoryUrl);

            // Indicate the remote repository
            log.debug("\t\t" + remoteRepositoryUrl);
        }

        // Create the class path factory and add remote repositories
        File localRepositoryDirectory = new File(this.localRepository.getBasedir());
        ClassPathFactory classPathFactory = new ClassPathFactoryImpl(this.plexusContainer,
                this.repositorySystem, localRepositoryDirectory,
                remoteRepositories.toArray(new RemoteRepository[remoteRepositories.size()]));

        // Indicate the class path
        log.debug("\tClass path:");

        // Obtain the class path entries for each included artifact
        List<String> classPathEntries = new LinkedList<String>();
        for (Artifact dependency : artifactInclusions) {

            // Obtain the class path entries for the dependency
            String[] entries = classPathFactory.createArtifactClassPath(dependency.getGroupId(),
                    dependency.getArtifactId(), dependency.getVersion(), dependency.getType(),
                    dependency.getClassifier());

            // Uniquely include the class path entries
            for (String entry : entries) {
                if (classPathEntries.contains(entry)) {
                    continue; // ignore as already included
                }
                classPathEntries.add(entry);

                // Indicate class path entry
                log.debug("\t\t" + entry);
            }
        }

        // Obtain the class path
        classPath = ClassPathFactoryImpl.transformClassPathEntriesToClassPath(
                classPathEntries.toArray(new String[classPathEntries.size()]));

    } catch (Exception ex) {
        throw newMojoExecutionException("Failed obtaining dependencies for launching OfficeBuilding", ex);
    }

    // Create the process configuration
    ProcessConfiguration configuration = new ProcessConfiguration();
    configuration.setAdditionalClassPath(classPath);

    // Write output to file
    configuration.setProcessOutputStreamFactory(new ProcessOutputStreamFactory() {

        @Override
        public OutputStream createStandardProcessOutputStream(String processNamespace, String[] command)
                throws IOException {

            // Log the command
            StringBuilder commandLine = new StringBuilder();
            commandLine.append(OfficeBuilding.class.getSimpleName() + " command line:");
            for (String commandItem : command) {
                commandLine.append(" ");
                commandLine.append(commandItem);
            }
            log.debug(commandLine);

            // Return the output stream
            return this.getOutputStream(processNamespace);
        }

        @Override
        public OutputStream createErrorProcessOutputStream(String processNamespace) throws IOException {
            return this.getOutputStream(processNamespace);
        }

        /**
         * Lazy instantiated {@link OutputStream}.
         */
        private OutputStream outputStream = null;

        /**
         * Obtains the {@link OutputStream}.
         * 
         * @param processNamespace
         *            Process name space.
         * @return {@link OutputStream}.
         * @throws IOException
         *             If fails to obtain the {@link OutputStream}.
         */
        private synchronized OutputStream getOutputStream(String processNamespace) throws IOException {

            // Lazy instantiate the output stream
            if (this.outputStream == null) {

                // Create the output file
                File file = File.createTempFile(processNamespace, ".log");
                this.outputStream = new FileOutputStream(file);

                // Log that outputting to file
                log.info("Logging " + OfficeBuilding.class.getSimpleName() + " output to file "
                        + file.getAbsolutePath());
            }

            // Return the output stream
            return this.outputStream;
        }
    });

    // Start the OfficeBuilding
    try {
        OfficeBuildingManager.spawnOfficeBuilding(null, this.port.intValue(), getKeyStoreFile(),
                KEY_STORE_PASSWORD, USER_NAME, PASSWORD, null, false, environment, null, true, configuration);
    } catch (Throwable ex) {
        // Provide details of the failure
        final String MESSAGE = "Failed starting the " + OfficeBuilding.class.getSimpleName();
        this.getLog().error(MESSAGE + ": " + ex.getMessage() + " [" + ex.getClass().getSimpleName() + "]");
        this.getLog().error("DIAGNOSIS INFORMATION:");
        this.getLog().error("   classpath='" + System.getProperty("java.class.path") + "'");
        this.getLog().error("   additional classpath='" + classPath + "'");

        // Propagate the failure
        throw newMojoExecutionException(MESSAGE, ex);
    }

    // Log started OfficeBuilding
    this.getLog().info("Started " + OfficeBuilding.class.getSimpleName() + " on port " + this.port.intValue());
}

From source file:org.eclipse.tycho.core.resolver.TychoMirrorSelector.java

License:Open Source License

private boolean isPrefixMirrorOf(ArtifactRepository repo, Mirror mirror) {
    boolean isMirrorOfRepoUrl = repo.getUrl() != null && repo.getUrl().startsWith(mirror.getMirrorOf());
    boolean matchesLayout = repo.getLayout() != null
            && repo.getLayout().getId().equals(mirror.getMirrorOfLayouts());
    return isMirrorOfRepoUrl && matchesLayout;
}

From source file:org.eclipse.tycho.p2.facade.P2TargetPlatformResolver.java

License:Open Source License

protected TargetPlatform doResolvePlatform(final MavenSession session, final MavenProject project,
        List<ReactorProject> reactorProjects, List<Dependency> dependencies, P2Resolver resolver) {
    TargetPlatformConfiguration configuration = (TargetPlatformConfiguration) project
            .getContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION);

    resolver.setRepositoryCache(repositoryCache);

    resolver.setOffline(session.isOffline());

    resolver.setLogger(new P2Logger() {
        public void debug(String message) {
            if (message != null && message.length() > 0) {
                getLogger().info(message); // TODO
            }/*from  w  w w.j a v a  2  s . c  om*/
        }

        public void info(String message) {
            if (message != null && message.length() > 0) {
                getLogger().info(message);
            }
        }

        public boolean isDebugEnabled() {
            return getLogger().isDebugEnabled() && DebugUtils.isDebugEnabled(session, project);
        }
    });

    Map<File, ReactorProject> projects = new HashMap<File, ReactorProject>();

    resolver.setLocalRepositoryLocation(new File(session.getLocalRepository().getBasedir()));

    resolver.setEnvironments(getEnvironments(configuration));

    for (ReactorProject otherProject : reactorProjects) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("P2resolver.addMavenProject " + otherProject.getId());
        }
        projects.put(otherProject.getBasedir(), otherProject);
        resolver.addReactorArtifact(new ReactorArtifactFacade(otherProject, null));

        Map<String, Set<Object>> dependencyMetadata = otherProject.getDependencyMetadata();
        if (dependencyMetadata != null) {
            for (String classifier : dependencyMetadata.keySet()) {
                resolver.addReactorArtifact(new ReactorArtifactFacade(otherProject, classifier));
            }
        }
    }

    if (dependencies != null) {
        for (Dependency dependency : dependencies) {
            resolver.addDependency(dependency.getType(), dependency.getArtifactId(), dependency.getVersion());
        }
    }

    if (TargetPlatformConfiguration.POM_DEPENDENCIES_CONSIDER.equals(configuration.getPomDependencies())) {
        Set<String> projectIds = new HashSet<String>();
        for (ReactorProject p : reactorProjects) {
            String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion());
            projectIds.add(key);
        }

        ArrayList<String> scopes = new ArrayList<String>();
        scopes.add(Artifact.SCOPE_COMPILE);
        Collection<Artifact> artifacts;
        try {
            artifacts = projectDependenciesResolver.resolve(project, scopes, session);
        } catch (MultipleArtifactsNotFoundException e) {
            Collection<Artifact> missing = new HashSet<Artifact>(e.getMissingArtifacts());

            for (Iterator<Artifact> it = missing.iterator(); it.hasNext();) {
                Artifact a = it.next();
                String key = ArtifactUtils.key(a.getGroupId(), a.getArtifactId(), a.getBaseVersion());
                if (projectIds.contains(key)) {
                    it.remove();
                }
            }

            if (!missing.isEmpty()) {
                throw new RuntimeException("Could not resolve project dependencies", e);
            }

            artifacts = e.getResolvedArtifacts();
            artifacts.removeAll(e.getMissingArtifacts());
        } catch (AbstractArtifactResolutionException e) {
            throw new RuntimeException("Could not resolve project dependencies", e);
        }
        List<Artifact> externalArtifacts = new ArrayList<Artifact>(artifacts.size());
        for (Artifact artifact : artifacts) {
            String key = ArtifactUtils.key(artifact.getGroupId(), artifact.getArtifactId(),
                    artifact.getBaseVersion());
            if (projectIds.contains(key)) {
                // resolved to an older snapshot from the repo, we only want the current project in the reactor
                continue;
            }
            externalArtifacts.add(artifact);
        }
        addToP2ViewOfLocalRepository(session, externalArtifacts, project);
        for (Artifact artifact : externalArtifacts) {
            /*
             * TODO This call generates p2 metadata for the POM dependencies. If the artifact
             * has an attached p2metadata.xml, we should reuse that metadata.
             */
            /*
             * TODO The generated metadata is "depencency only" metadata. (Just by coincidence
             * this is currently full metadata.) Since this POM depencency metadata may be
             * copied into an eclipse-repository or p2-enabled RCP installation, it shall be
             * documented that the generated metadata must be full metadata.
             */
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("P2resolver.addMavenArtifact " + artifact.toString());
            }
            resolver.addMavenArtifact(new ArtifactFacade(artifact));
        }
    }

    for (ArtifactRepository repository : project.getRemoteArtifactRepositories()) {
        try {
            URI uri = new URL(repository.getUrl()).toURI();

            if (repository.getLayout() instanceof P2ArtifactRepositoryLayout) {
                if (session.isOffline()) {
                    getLogger().debug("Offline mode, using local cache only for repository "
                            + repository.getId() + " (" + repository.getUrl() + ")");
                }

                try {
                    Authentication auth = repository.getAuthentication();
                    if (auth != null) {
                        resolver.setCredentials(uri, auth.getUsername(), auth.getPassword());
                    }

                    resolver.addP2Repository(uri);

                    getLogger().debug(
                            "Added p2 repository " + repository.getId() + " (" + repository.getUrl() + ")");
                } catch (Exception e) {
                    String msg = "Failed to access p2 repository " + repository.getId() + " ("
                            + repository.getUrl() + "), will try to use local cache. Reason: " + e.getMessage();
                    if (getLogger().isDebugEnabled()) {
                        getLogger().warn(msg, e);
                    } else {
                        getLogger().warn(msg);
                    }
                }
            } else {
                if (!configuration.isIgnoreTychoRepositories() && !session.isOffline()) {
                    try {
                        MavenRepositoryReader reader = plexus.lookup(MavenRepositoryReader.class);
                        reader.setArtifactRepository(repository);
                        reader.setLocalRepository(session.getLocalRepository());

                        String repositoryKey = getRepositoryKey(repository);
                        TychoRepositoryIndex index = repositoryCache.getRepositoryIndex(repositoryKey);
                        if (index == null) {
                            index = new DefaultTychoRepositoryIndex(reader);

                            repositoryCache.putRepositoryIndex(repositoryKey, index);
                        }

                        resolver.addMavenRepository(uri, index, reader);
                        getLogger().debug("Added Maven repository " + repository.getId() + " ("
                                + repository.getUrl() + ")");
                    } catch (FileNotFoundException e) {
                        // it happens
                    } catch (Exception e) {
                        getLogger().debug("Unable to initialize remote Tycho repository", e);
                    }
                } else {
                    String msg = "Ignoring Maven repository " + repository.getId() + " (" + repository.getUrl()
                            + ")";
                    if (session.isOffline()) {
                        msg += " while in offline mode";
                    }
                    getLogger().debug(msg);
                }
            }
        } catch (MalformedURLException e) {
            getLogger().warn("Could not parse repository URL", e);
        } catch (URISyntaxException e) {
            getLogger().warn("Could not parse repository URL", e);
        }
    }

    Target target = configuration.getTarget();

    if (target != null) {
        Set<URI> uris = new HashSet<URI>();

        for (Target.Location location : target.getLocations()) {
            String type = location.getType();
            if (!"InstallableUnit".equalsIgnoreCase(type)) {
                getLogger().warn("Target location type: " + type + " is not supported");
                continue;
            }
            for (Target.Repository repository : location.getRepositories()) {

                try {
                    URI uri = new URI(getMirror(repository, session.getRequest().getMirrors()));
                    if (uris.add(uri)) {
                        if (session.isOffline()) {
                            getLogger().debug("Ignored repository " + uri + " while in offline mode");
                        } else {
                            String id = repository.getId();
                            if (id != null) {
                                Server server = session.getSettings().getServer(id);

                                if (server != null) {
                                    resolver.setCredentials(uri, server.getUsername(), server.getPassword());
                                } else {
                                    getLogger().info("Unknown server id=" + id + " for repository location="
                                            + repository.getLocation());
                                }
                            }

                            try {
                                resolver.addP2Repository(uri);
                            } catch (Exception e) {
                                String msg = "Failed to access p2 repository " + uri
                                        + ", will try to use local cache. Reason: " + e.getMessage();
                                if (getLogger().isDebugEnabled()) {
                                    getLogger().warn(msg, e);
                                } else {
                                    getLogger().warn(msg);
                                }
                            }
                        }
                    }
                } catch (URISyntaxException e) {
                    getLogger().debug("Could not parse repository URL", e);
                }
            }

            for (Target.Unit unit : location.getUnits()) {
                String versionRange;
                if ("0.0.0".equals(unit.getVersion())) {
                    versionRange = unit.getVersion();
                } else {
                    // perfect version match
                    versionRange = "[" + unit.getVersion() + "," + unit.getVersion() + "]";
                }
                resolver.addDependency(P2Resolver.TYPE_INSTALLABLE_UNIT, unit.getId(), versionRange);
            }
        }
    }

    if (!isAllowConflictingDependencies(project, configuration)) {
        List<P2ResolutionResult> results = resolver.resolveProject(project.getBasedir());

        MultiEnvironmentTargetPlatform multiPlatform = new MultiEnvironmentTargetPlatform();

        // FIXME this is just wrong
        for (int i = 0; i < configuration.getEnvironments().size(); i++) {
            TargetEnvironment environment = configuration.getEnvironments().get(i);
            P2ResolutionResult result = results.get(i);

            DefaultTargetPlatform platform = newDefaultTargetPlatform(session, projects, result);

            // addProjects( session, platform );

            multiPlatform.addPlatform(environment, platform);
        }

        return multiPlatform;
    } else {
        P2ResolutionResult result = resolver.collectProjectDependencies(project.getBasedir());

        return newDefaultTargetPlatform(session, projects, result);
    }
}

From source file:org.eclipse.tycho.p2.resolver.P2DependencyResolver.java

License:Open Source License

private void addEntireP2RepositoryToTargetPlatform(ArtifactRepository repository,
        TargetPlatformConfigurationStub resolutionContext) {
    try {//  ww w .  j  av  a2 s . co  m
        if (repository.getLayout() instanceof P2ArtifactRepositoryLayout) {
            URI url = new URL(repository.getUrl()).toURI();
            resolutionContext.addP2Repository(new MavenRepositoryLocation(repository.getId(), url));

            getLogger().debug("Added p2 repository " + repository.getId() + " (" + repository.getUrl() + ")");
        }
    } catch (MalformedURLException e) {
        throw new RuntimeException("Invalid repository URL: " + repository.getUrl(), e);
    } catch (URISyntaxException e) {
        throw new RuntimeException("Invalid repository URL: " + repository.getUrl(), e);
    }
}

From source file:org.eclipse.tycho.p2.resolver.P2TargetPlatformResolver.java

License:Open Source License

private void addEntireP2RepositoryToTargetPlatform(ArtifactRepository repository,
        TargetPlatformBuilder resolutionContext, MavenSession session) {
    try {/*from www.ja  va2s  .  c o  m*/
        URI uri = new URL(repository.getUrl()).toURI();

        if (repository.getLayout() instanceof P2ArtifactRepositoryLayout) {
            if (session.isOffline()) {
                getLogger().debug("Offline mode, using local cache only for repository " + repository.getId()
                        + " (" + repository.getUrl() + ")");
            }

            try {
                Authentication auth = repository.getAuthentication();
                if (auth != null) {
                    resolutionContext.setCredentials(uri, auth.getUsername(), auth.getPassword());
                }

                resolutionContext.addP2Repository(uri);

                getLogger()
                        .debug("Added p2 repository " + repository.getId() + " (" + repository.getUrl() + ")");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    } catch (MalformedURLException e) {
        getLogger().warn("Could not parse repository URL", e);
    } catch (URISyntaxException e) {
        getLogger().warn("Could not parse repository URL", e);
    }
}

From source file:org.eclipse.tycho.versionbump.UpdateProductMojo.java

License:Open Source License

@Override
protected void doUpdate(P2ResolverFactory factory) throws IOException, URISyntaxException {
    P2Resolver p2 = newResolver(factory);

    for (ArtifactRepository repository : project.getRemoteArtifactRepositories()) {
        URI uri = new URL(repository.getUrl()).toURI();

        if (repository.getLayout() instanceof P2ArtifactRepositoryLayout) {
            Authentication auth = repository.getAuthentication();
            if (auth != null) {
                p2.setCredentials(uri, auth.getUsername(), auth.getPassword());
            }/*from  ww  w  .j av  a  2s  . c o m*/

            p2.addP2Repository(uri);
        }
    }

    ProductConfiguration product = ProductConfiguration.read(productFile);

    for (PluginRef plugin : product.getPlugins()) {
        p2.addDependency(P2Resolver.TYPE_ECLIPSE_PLUGIN, plugin.getId(), "0.0.0");
    }

    P2ResolutionResult result = p2.resolveMetadata(getEnvironments().get(0));

    Map<String, String> ius = new HashMap<String, String>();
    for (P2ResolutionResult.Entry entry : result.getArtifacts()) {
        ius.put(entry.getId(), entry.getVersion());
    }

    for (PluginRef plugin : product.getPlugins()) {
        String version = ius.get(plugin.getId());
        if (version != null) {
            plugin.setVersion(version);
        }
    }

    ProductConfiguration.write(product, productFile);
}