Java Code Examples for org.apache.maven.model.Repository#setId()

The following examples show how to use org.apache.maven.model.Repository#setId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RepositoryLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
/**
 * Construct repository instance from given url. Query parameters are translated to fields on the target repository.
 * @param id
 * @param url
 * @param logger
 * @return
 */
default Repository build(String id, String url, Logger logger) throws LifecycleExecutionException {
    Repository repository = new Repository();

    repository.setId(id);

    try {
        URL configurationUrl = new URL(url);
        repository.setUrl(String.format("%s://%s%s", configurationUrl.getProtocol(), configurationUrl.getHost(), configurationUrl.getPath()));
    } catch (MalformedURLException e) {
        throw new LifecycleExecutionException("Failed to construct Maven repository model from given URL", e);
    }

    logger.info(String.format("Add Repository %s=%s", repository.getId(), repository.getUrl()));
    return repository;
}
 
Example 2
Source File: TestHelper.java    From yaks with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that default mock repositories are present in the given list od repositories. This verification can be shared by multiple
 * tests that load the repository list in different ways (e.g. via Json, Yaml, System properties, ...)
 * @param repositoryList
 */
public static void verifyRepositories(List<Repository> repositoryList) {
    Repository central = new Repository();
    central.setId("central");
    central.setName("Maven Central");
    central.setUrl("https://repo.maven.apache.org/maven2/");

    Repository jboss = new Repository();
    jboss.setId("jboss-ea");
    jboss.setName("JBoss Community Early Access Release Repository");
    jboss.setUrl("https://repository.jboss.org/nexus/content/groups/ea/");

    Assertions.assertThat(repositoryList).hasSize(2);
    Assertions.assertThat(repositoryList).anyMatch(repository -> repository.getId().equals(central.getId()));
    Assertions.assertThat(repositoryList).anyMatch(repository -> repository.getUrl().equals(central.getUrl()));
    Assertions.assertThat(repositoryList).anyMatch(repository -> repository.getId().equals(jboss.getId()));
    Assertions.assertThat(repositoryList).anyMatch(repository -> repository.getUrl().equals(jboss.getUrl()));
}
 
Example 3
Source File: YamlFileRepositoryLoader.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Repository> load(Path filePath, Logger logger) throws LifecycleExecutionException {
    try {
        List<Repository> repositoryList = new ArrayList<>();
        Yaml yaml = new Yaml();

        HashMap<String, List<Map<String, Object>>> root = yaml.load(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8)));
        if (root.containsKey("repositories")) {
            for (Map<String, Object> model : root.get("repositories")) {
                Repository repository = new Repository();

                repository.setId(Objects.toString(model.get("id")));
                repository.setName(Objects.toString(model.getOrDefault("name", repository.getId())));
                repository.setUrl(Objects.toString(model.get("url")));
                repository.setLayout(Objects.toString(model.getOrDefault("layout", "default")));

                if (model.containsKey("releases")) {
                    repository.setReleases(getRepositoryPolicy((Map<String, Object>) model.get("releases")));
                }

                if (model.containsKey("snapshots")) {
                    repository.setReleases(getRepositoryPolicy((Map<String, Object>) model.get("snapshots")));
                }

                logger.info(String.format("Add Repository %s=%s", repository.getId(), repository.getUrl()));
                repositoryList.add(repository);
            }
        }

        return repositoryList;
    } catch (IOException e) {
        throw new LifecycleExecutionException("Failed to read repository configuration file", e);
    }
}
 
Example 4
Source File: JsonFileRepositoryLoader.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Repository> load(Path filePath, Logger logger) throws LifecycleExecutionException {
    List<Repository> repositoryList = new ArrayList<>();

    ObjectMapper mapper = new ObjectMapper();
    try {
        JsonNode root = mapper.readTree(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8)));
        ArrayNode repositories = (ArrayNode) root.get("repositories");
        for (Object o : repositories) {
            ObjectNode model = (ObjectNode) o;
            Repository repository = new Repository();

            repository.setId(model.get("id").textValue());
            repository.setUrl(model.get("url").textValue());

            if (model.get("name") != null) {
                repository.setName(model.get("name").textValue());
            }

            if (model.get("layout") != null) {
                repository.setLayout(model.get("layout").textValue());
            }

            if (model.get("releases") != null) {
                repository.setReleases(getRepositoryPolicy((ObjectNode) model.get("releases")));
            }

            if (model.get("snapshots") != null) {
                repository.setReleases(getRepositoryPolicy((ObjectNode) model.get("snapshots")));
            }

            logger.info(String.format("Add Repository %s=%s", repository.getId(), repository.getUrl()));
            repositoryList.add(repository);
        }
    } catch (IOException e) {
        throw new LifecycleExecutionException("Failed to read json repository config file", e);
    }

    return repositoryList;
}
 
Example 5
Source File: DefaultModelResolver.java    From migration-tooling with Apache License 2.0 5 votes vote down vote up
/** Adds a user-specified repository to the list. */
public void addUserRepository(String url) {
  Repository repository = new Repository();
  repository.setUrl(url);
  repository.setId("user-defined repository");
  repository.setName("default");
  addRepository(repository);
  this.aether.addRemoteRepository(
      new RemoteRepository.Builder("user-defined repository", "default", url).build());
}
 
Example 6
Source File: BuildManager.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private Repository createRepo(String id, String url, String layout) {
	Repository repo = new Repository();
	repo.setId(id);
	repo.setUrl(url);
	repo.setLayout(layout);
	return repo;
}
 
Example 7
Source File: AbstractWSO2ProjectCreationWizard.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
protected Repository getGlobalRepositoryFromPreference() {

		String repoURL =
		                 preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
		                                              GLOBAL_REPOSITORY_URL, null, null);
		if (repoURL != null) {
			Repository repo = new Repository();
			repo.setUrl(repoURL);
			repo.setId(preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
			                                        GLOBAL_REPOSITORY_ID, null, null));
			RepositoryPolicy releasePolicy = new RepositoryPolicy();
			String releaseEnabled =
			                        preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
			                                                     RELEASES_ENABLED, null, null);
			releasePolicy.setEnabled(releaseEnabled != null);
			releasePolicy.setUpdatePolicy(preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
			                                                           RELEASES_UPDATE_POLICY, null, null));
			releasePolicy.setChecksumPolicy(preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
			                                                             RELEASES_CHECKSUM_POLICY, null, null));
			repo.setReleases(releasePolicy);

			RepositoryPolicy snapshotPolicy = new RepositoryPolicy();
			String snapshotsEnabled =
			                          preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
			                                                       SNAPSHOTS_ENABLED, null, null);
			snapshotPolicy.setEnabled(snapshotsEnabled != null);
			snapshotPolicy.setUpdatePolicy(preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
			                                                            SNAPSHOTS_UPDATE_POLICY, null, null));
			snapshotPolicy.setChecksumPolicy(preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
			                                                              SNAPSHOTS_CHECKSUM_POLICY, null, null));
			repo.setSnapshots(snapshotPolicy);

			return repo;
		}
		return null;
	}
 
Example 8
Source File: MavenUtils.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public static void updateMavenProjectWithWSO2Repository(MavenProject mavenProject){
	Repository repo = new Repository();
	repo.setUrl("http://maven.wso2.org/nexus/content/groups/wso2-public/");
	repo.setId("wso2-maven2-repository-1");

	mavenProject.getModel().addRepository(repo);
	mavenProject.getModel().addPluginRepository(repo);
}
 
Example 9
Source File: RepoAndReportingRemovalManipulator.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private void processRepository( ManipulationSession session, Project project, Repository repository )
                throws ManipulationException
{
    repository.setUrl( PropertyResolver.resolveInheritedProperties( session, project, repository.getUrl() ) );
    repository.setId( PropertyResolver.resolveInheritedProperties( session, project, repository.getId() ) );
    repository.setName( PropertyResolver.resolveInheritedProperties( session, project, repository.getName() ) );
    if (isBlank( repository.getName() ) )
    {
        repository.setName( repository.getId() );
    }
}