private RemoteRepository convertToArtifactRepository( final org.apache.maven.artifact.repository.ArtifactRepository artifactRepository) { final MavenEmbedder mavenEmbedder = MavenProjectLoader.newMavenEmbedder(MavenSettings.getSettings().isOffline()); final RemoteRepository.Builder remoteRepoBuilder = new RemoteRepository.Builder( artifactRepository.getId(), artifactRepository.getLayout().getId(), artifactRepository.getUrl()) .setSnapshotPolicy( new RepositoryPolicy( true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN)) .setReleasePolicy( new RepositoryPolicy( true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_WARN)); final Settings settings = MavenSettings.getSettings(); final Server server = settings.getServer(artifactRepository.getId()); if (server != null) { final Authentication authentication = mavenEmbedder .getMavenSession() .getRepositorySession() .getAuthenticationSelector() .getAuthentication(remoteRepoBuilder.build()); remoteRepoBuilder.setAuthentication(authentication); } return remoteRepoBuilder.build(); }
@Override public Set<MavenRepositoryMetadata> getRepositoriesResolvingArtifact( final String pomXML, final MavenRepositoryMetadata... filter) { GAVPreferences gavPreferences = gavPreferencesProvider.get(); gavPreferences.load(); if (gavPreferences.isConflictingGAVCheckDisabled()) { return Collections.EMPTY_SET; } final InputStream pomStream = new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8)); final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream); final GAV gav = new GAV(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); final Set<MavenRepositoryMetadata> repositoriesResolvingArtifact = new HashSet<MavenRepositoryMetadata>(); repositoriesResolvingArtifact.addAll(getRepositoriesResolvingArtifact(gav, mavenProject)); // Filter results if necessary if (filter != null && filter.length > 0) { repositoriesResolvingArtifact.retainAll(Arrays.asList(filter)); } return repositoriesResolvingArtifact; }
/* * Build Maven Project from Source using Out and Err PrintStreams for getting the output */ private void buildMavenProject(Source source, PrintStream out, PrintStream err) throws org.uberfire.java.nio.IOException, InvalidPathException, SecurityException, UnsupportedOperationException, IllegalArgumentException { List<String> goals = new ArrayList<>(); goals.add("package"); Properties p = new Properties(); p.setProperty("failIfNoTests", "false"); final InputStream pomStream = org.uberfire.java.nio.file.Files.newInputStream( source.getPath().resolve("drools-webapp-example").resolve("pom.xml")); MavenProject project = MavenProjectLoader.parseMavenPom(pomStream); final String expectedBinary = project.getArtifact().getArtifactId() + "-" + project.getArtifact().getVersion() + "." + project.getArtifact().getType(); final org.guvnor.ala.build.maven.model.MavenProject mavenProject = new MavenProjectImpl( project.getId(), project.getArtifact().getType(), project.getName(), expectedBinary, source.getPath(), source.getPath().resolve("drools-webapp-example"), source.getPath().resolve("target").resolve(expectedBinary).toAbsolutePath(), null, null); final File pom = new File(getRepositoryVisitor(mavenProject).getRoot(), "pom.xml"); MavenBuildExecutor.executeMaven(pom, out, err, p, goals.toArray(new String[0])); }
@Override public Set<MavenRepositoryMetadata> getRepositoriesResolvingArtifact( final GAV gav, final Project project, final MavenRepositoryMetadata... filter) { GAVPreferences gavPreferences = gavPreferencesProvider.get(); final PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo = scopeResolutionStrategies.getUserInfoFor( GuvnorPreferenceScopes.PROJECT, project.getEncodedIdentifier()); gavPreferences.load(scopeResolutionStrategyInfo); if (gavPreferences.isConflictingGAVCheckDisabled()) { return Collections.EMPTY_SET; } final Set<MavenRepositoryMetadata> repositoriesResolvingArtifact = new HashSet<MavenRepositoryMetadata>(); try { // Load Project's pom.xml final Path pomXMLPath = project.getPomXMLPath(); final org.uberfire.java.nio.file.Path nioPomXMLPath = Paths.convert(pomXMLPath); final String pomXML = ioService.readAllString(nioPomXMLPath); final InputStream pomStream = new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8)); final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream); repositoriesResolvingArtifact.addAll(getRepositoriesResolvingArtifact(gav, mavenProject)); // Filter results if necessary if (filter != null && filter.length > 0) { repositoriesResolvingArtifact.retainAll(Arrays.asList(filter)); } } catch (IllegalArgumentException iae) { log.error( "Unable to get Remote Repositories for Project '" + project.getProjectName() + "'. Returning empty Collection. ", iae); } catch (NoSuchFileException nsfe) { log.error( "Unable to get Remote Repositories for Project '" + project.getProjectName() + "'. Returning empty Collection. ", nsfe); } catch (org.uberfire.java.nio.IOException ioe) { log.error( "Unable to get Remote Repositories for Project '" + project.getProjectName() + "'. Returning empty Collection. ", ioe); } return repositoriesResolvingArtifact; }
@Override public Set<MavenRepositoryMetadata> getRemoteRepositoriesMetaData(final Project project) { if (project == null) { return Collections.emptySet(); } final Set<MavenRepositoryMetadata> repositories = new HashSet<MavenRepositoryMetadata>(); try { // Load Project's pom.xml final Path pomXMLPath = project.getPomXMLPath(); final org.uberfire.java.nio.file.Path nioPomXMLPath = Paths.convert(pomXMLPath); final String pomXML = ioService.readAllString(nioPomXMLPath); final InputStream pomStream = new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8)); final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream); final Aether aether = new Aether(mavenProject); final Map<MavenRepositorySource, Collection<RemoteRepository>> remoteRepositories = getRemoteRepositories(mavenProject); // Local Repository repositories.add( makeRepositoryMetaData( aether.getSession().getLocalRepository(), MavenRepositorySource.LOCAL)); if (remoteRepositories.isEmpty()) { return repositories; } for (Map.Entry<MavenRepositorySource, Collection<RemoteRepository>> e : remoteRepositories.entrySet()) { repositories.addAll(makeRepositoriesMetaData(e.getValue(), e.getKey())); } } catch (IllegalArgumentException iae) { log.error( "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ", project.getProjectName(), iae); } catch (NoSuchFileException nsfe) { log.error( "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ", project.getProjectName(), nsfe); } catch (org.uberfire.java.nio.IOException ioe) { log.error( "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ", project.getProjectName(), ioe); } return repositories; }
@Override public Set<MavenRepositoryMetadata> getRepositoriesResolvingArtifact( final GAV gav, final MavenRepositoryMetadata... filter) { GAVPreferences gavPreferences = gavPreferencesProvider.get(); gavPreferences.load(); if (gavPreferences.isConflictingGAVCheckDisabled()) { return Collections.EMPTY_SET; } final Set<MavenRepositoryMetadata> repositoriesResolvingArtifact = new HashSet<MavenRepositoryMetadata>(); try { // Construct the Project's pom.xml final String pomXML = pomContentHandler.toString(new POM(gav)); final InputStream pomStream = new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8)); final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream); repositoriesResolvingArtifact.addAll(getRepositoriesResolvingArtifact(gav, mavenProject)); // Filter results if necessary if (filter != null && filter.length > 0) { repositoriesResolvingArtifact.retainAll(Arrays.asList(filter)); } } catch (IOException ioe) { log.error( "Unable to get Remote Repositories for Project '" + gav.toString() + "'. Returning empty Collection. ", ioe); } return repositoriesResolvingArtifact; }