org.apache.maven.model.Repository Java Examples

The following examples show how to use org.apache.maven.model.Repository. 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: ProjectModelReader.java    From yaks with Apache License 2.0 6 votes vote down vote up
/**
 * Dynamically add project repositories based on different configuration sources such as environment variables,
 * system properties configuration files.
 */
private List<Repository> loadDynamicRepositories() {
    if (repositoryList == null) {
        repositoryList = new ArrayList<>();
        logger.info("Add dynamic project repositories ...");

        try {
            repositoryList.addAll(new FileBasedRepositoryLoader().load(logger));
            repositoryList.addAll(new SystemPropertyRepositoryLoader().load(logger));
            repositoryList.addAll(new EnvironmentSettingRepositoryLoader().load(logger));
        } catch (LifecycleExecutionException e) {
            throw new RuntimeException(e);
        }
    }

    return repositoryList;
}
 
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: RepoAndReportingRemovalManipulator.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
/**
 * Examine the repository to see if we should not remove it.
 * @param state to query the ignoreLocal value
 * @param repo the repository to examine
 * @return boolean whether to remove this repository
 */
private boolean removeRepository (RepoReportingState state, Repository repo)
{
    boolean result = true;

    if (state.ignoreLocal())
    {
        String url = repo.getUrl();
        // According to https://maven.apache.org/plugins/maven-site-plugin/examples/adding-deploy-protocol.html
        // supported repositories are file, http and https.
        if (url.startsWith( "file:" ) ||
            url.startsWith( "http://localhost" ) ||
            url.startsWith( "https://localhost" ) ||
            url.startsWith( "http://127.0.0.1" ) ||
            url.startsWith( "https://127.0.0.1" ) ||
            url.startsWith( "http://::1" ) ||
            url.startsWith( "https://::1" ) )
        {
            result = false;
        }
    }
    return result;
}
 
Example #4
Source File: ResolvableDependency.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
private static SortedSet<DefaultArtifactVersion> resolveVersions(final MavenProject project, final Log log, final ResolvableDependency dependency) throws MojoExecutionException {
  final List<Repository> repositories = project.getRepositories();
  final SortedSet<DefaultArtifactVersion> allVersions = new TreeSet<>();
  for (final Repository repository : repositories) {
    final DependencyId dependencyId = new DependencyId(dependency, repository);
    final SortedSet<DefaultArtifactVersion> versions;
    if (dependencyIdToVersions.containsKey(dependencyId))
      versions = dependencyIdToVersions.get(dependencyId);
    else
      dependencyIdToVersions.put(dependencyId, versions = downloadVersions(log, dependencyId));

    if (versions != null)
      allVersions.addAll(versions);
  }

  if (allVersions.size() == 0)
    throw new MojoExecutionException("Artifact " + dependency.getGroupId() + ":" + dependency.getArtifactId() + " was not found in any repositories:\n" + AssembleUtil.toIndentedString(repositories));

  return allVersions;
}
 
Example #5
Source File: RepositoryInjectionManipulator.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
/**
 * Add the repository to the list of repositories. If an existing repository has the same
 * id it is removed first.
 *
 * @param repositories the current list of repositories
 * @param repository the repository to add
 */
private void addRepository( final List<Repository> repositories, final Repository repository )
{
    final Iterator<Repository> i = repositories.iterator();
    while ( i.hasNext() )
    {
        final Repository r = i.next();

        if ( repository.getId().equals( r.getId() ) )
        {
            logger.debug("Removing local repository {} ", r);
            i.remove();
            break;
        }
    }

    logger.debug( "Adding repository {}", repository );
    repositories.add(repository);
}
 
Example #6
Source File: MavenModelResolver.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void addRepository(final Repository repository, boolean replace) throws InvalidRepositoryException
{
   if (session.isIgnoreArtifactDescriptorRepositories())
   {
      return;
   }

   if (!repositoryIds.add(repository.getId()))
   {
      if (!replace)
      {
         return;
      }

      removeMatchingRepository(repository.getId());
   }
   repositories.add(new RemoteRepository.Builder(repository.getId(), repository.getName(), repository.getUrl())
            .build());
}
 
Example #7
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 #8
Source File: FlattenMojo.java    From flatten-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * This method determines if the given {@link Repository} section is identical to what is defined from the super
 * POM.
 *
 * @param repo is the {@link Repository} section to check.
 * @return <code>true</code> if maven central default configuration, <code>false</code> otherwise.
 */
private static boolean isCentralRepositoryFromSuperPom( Repository repo )
{
    if ( repo != null )
    {
        if ( "central".equals( repo.getId() ) )
        {
            RepositoryPolicy snapshots = repo.getSnapshots();
            if ( snapshots != null && !snapshots.isEnabled() )
            {
                return true;
            }
        }
    }
    return false;
}
 
Example #9
Source File: FlattenMojo.java    From flatten-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a flattened {@link List} of {@link Repository} elements where those from super-POM are omitted.
 *
 * @param repositories is the {@link List} of {@link Repository} elements. May be <code>null</code>.
 * @return the flattened {@link List} of {@link Repository} elements or <code>null</code> if <code>null</code> was
 *         given.
 */
protected static List<Repository> createFlattenedRepositories( List<Repository> repositories )
{
    if ( repositories != null )
    {
        List<Repository> flattenedRepositories = new ArrayList<Repository>( repositories.size() );
        for ( Repository repo : repositories )
        {
            // filter inherited repository section from super POM (see MOJO-2042)...
            if ( !isCentralRepositoryFromSuperPom( repo ) )
            {
                flattenedRepositories.add( repo );
            }
        }
        return flattenedRepositories;
    }
    return repositories;
}
 
Example #10
Source File: SystemPropertyRepositoryLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Override
public List<Repository> load(Logger logger) throws LifecycleExecutionException {
    List<Repository> repositoryList = new ArrayList<>();

    String coordinates = System.getProperty(ExtensionSettings.REPOSITORIES_SETTING_KEY, "");

    if (coordinates.length() > 0) {
        for (String scalar : coordinates.split(",")) {
            String[] config = scalar.split("=");
            if (config.length == 2) {
                repositoryList.add(build(config[0], config[1], logger));
            }
        }

        if (!repositoryList.isEmpty()) {
            logger.info(String.format("Add %s repositories found in system properties", repositoryList.size()));
        }
    }

    return repositoryList;
}
 
Example #11
Source File: EnvironmentSettingRepositoryLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Override
public List<Repository> load(Logger logger) throws LifecycleExecutionException {
    List<Repository> repositoryList = new ArrayList<>();

    String settings = getEnvSetting(ExtensionSettings.REPOSITORIES_SETTING_ENV);

    if (settings.length() > 0) {
        for (String scalar : settings.split(",")) {
            String[] config = scalar.split("=");
            if (config.length == 2) {
                repositoryList.add(build(config[0], config[1], logger));
            }
        }

        if (!repositoryList.isEmpty()) {
            logger.info(String.format("Add %s repositories found in environment variables", repositoryList.size()));
        }
    }

    return repositoryList;
}
 
Example #12
Source File: MavenModelResolver.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void addRepository(Repository repository) throws InvalidRepositoryException
{
   if (repositoryIds.contains(repository.getId()))
   {
      return;
   }

   repositoryIds.add(repository.getId());
   repositories.add(new RemoteRepository.Builder(repository.getId(), repository.getName(), repository.getUrl())
            .build());
}
 
Example #13
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 #14
Source File: FileBasedRepositoryLoaderTest.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldLoadFromPropertyFile() throws LifecycleExecutionException {
    System.setProperty(ExtensionSettings.SETTINGS_FILE_KEY, "classpath:yaks.properties");
    List<Repository> repositoryList = loader.load(logger);
    TestHelper.verifyRepositories(repositoryList);

    System.setProperty(ExtensionSettings.SETTINGS_FILE_KEY, "classpath:yaks.settings.yaml");
    repositoryList = loader.load(logger);
    TestHelper.verifyRepositories(repositoryList);

    System.setProperty(ExtensionSettings.SETTINGS_FILE_KEY, "classpath:yaks.settings.json");
    repositoryList = loader.load(logger);
    TestHelper.verifyRepositories(repositoryList);
}
 
Example #15
Source File: EnvironmentSettingRepositoryLoaderTest.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldLoadFromEnv() throws LifecycleExecutionException {
    EnvironmentSettingRepositoryLoader loader = new EnvironmentSettingRepositoryLoader() {
        @Override
        protected String getEnvSetting(String name) {
            return "central=https://repo.maven.apache.org/maven2/,jboss-ea=https://repository.jboss.org/nexus/content/groups/ea/";
        }
    };

    List<Repository> repositoryList = loader.load(logger);
    TestHelper.verifyRepositories(repositoryList);
}
 
Example #16
Source File: MavenArtifactResolver.java    From javafx-maven-plugin with Apache License 2.0 5 votes vote down vote up
MavenArtifactResolver(List<Repository> repositories) {
    this.repositorySystem = createRepositorySystem();
    this.remoteRepositories = new LinkedList<>();
    repositories.forEach(r -> {
        RemoteRepository repository = new RemoteRepository
                .Builder(r.getId(), "default", r.getUrl())
                .build();
        remoteRepositories.add(repository);
    });
}
 
Example #17
Source File: AttachArtifactResolver.java    From client-maven-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Map<String, Artifact> findArtifactsForTarget(List<Dependency> dependencies, List<Repository> repositories, String target) {
    final MavenArtifactResolver resolver = new MavenArtifactResolver(repositories);
    return dependencies.stream()
            .filter(d -> DEPENDENCY_GROUP.equals(d.getGroupId()))
            .map(d -> {
                if (UTIL_ARTIFACT.equals(d.getArtifactId())) {
                    if (Constants.PROFILE_ANDROID.equals(target) ||
                        Constants.PROFILE_IOS.equals(target)||
                        Constants.PROFILE_IOS_SIM.equals(target)) {
                        return new DefaultArtifact(d.getGroupId(), d.getArtifactId(),
                                target, d.getType(), d.getVersion());
                    }
                    return  null;
                }
                AttachServiceDefinition asd = new AttachServiceDefinition(d.getArtifactId());
                return new DefaultArtifact(d.getGroupId(), d.getArtifactId(),
                        asd.getSupportedPlatform(target), d.getType(), d.getVersion());
            })
            .filter(Objects::nonNull)
            .flatMap(a -> {
                Set<Artifact> resolve = resolver.resolve(a);
                if (resolve == null) {
                    return Stream.empty();
                }
                return resolve.stream();
            })
            .distinct()
            .collect(Collectors.toMap(Artifact::getArtifactId, a -> a));
}
 
Example #18
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 #19
Source File: DefaultModelResolver.java    From migration-tooling with Apache License 2.0 5 votes vote down vote up
private DefaultModelResolver(
    Aether aether,
    Set<Repository> repositories,
    Map<String, ModelSource> ruleNameToModelSource,
    DefaultModelBuilder modelBuilder) {
  this.repositories = repositories;
  this.ruleNameToModelSource = ruleNameToModelSource;
  this.modelBuilder = modelBuilder;
  this.aether = aether;
  this.versionResolver = new VersionResolver(aether);
}
 
Example #20
Source File: FileBasedRepositoryLoader.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Override
public List<Repository> load(Logger logger) throws LifecycleExecutionException {
    Path settingsFile = getSettingsFile();

    if (Files.exists(settingsFile)) {
        Optional<String> fileExtension = getFileNameExtension(settingsFile.getFileName().toString());
        return fileExtension.flatMap(this::getFileConfigLoader)
                            .orElse(new PropertyFileRepositoryLoader())
                            .load(settingsFile, logger);
    }

    return Collections.emptyList();
}
 
Example #21
Source File: DefaultModelResolver.java    From migration-tooling with Apache License 2.0 5 votes vote down vote up
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
    throws UnresolvableModelException {
  String ruleName = Rule.name(groupId, artifactId);
  if (ruleNameToModelSource.containsKey(ruleName)) {
    return ruleNameToModelSource.get(ruleName);
  }
  for (Repository repository : repositories) {
    UrlModelSource modelSource =
        getModelSource(repository.getUrl(), groupId, artifactId, version);
    if (modelSource != null) {
      return modelSource;
    }
  }

  List<String> attemptedUrls = repositories.stream().map(Repository::getUrl).collect(toList());
  throw new UnresolvableModelException(
      "Could not find any repositories that knew how to "
          + "resolve "
          + groupId
          + ":"
          + artifactId
          + ":"
          + version
          + " (checked "
          + Joiner.on(", ").join(attemptedUrls)
          + ")",
      groupId,
      artifactId,
      version);
}
 
Example #22
Source File: AbstractWSO2ProjectCreationWizard.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public void createPOM(File pomLocation, String packagingType) throws Exception {
	MavenInfo mavenInfo = getModel().getMavenInfo();

	String customGroupId =
	                       preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
	                                                    GLOBAL_MAVEN_GROUP_ID, null, null);
	String customVersion =
	                       preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
	                                                    GLOBAL_MAVEN_VERSION, null, null);

	MavenProject mavenProject =
	                            MavenUtils.createMavenProject(customGroupId != null ? customGroupId
	                                                                               : mavenInfo.getGroupId(),
	                                                          mavenInfo.getArtifactId(),
	                                                          customVersion != null ? customVersion
	                                                                               : mavenInfo.getVersion(),
	                                                          packagingType);

	Parent parentProject = getModel().getMavenInfo().getParentProject();
	if (parentProject != null) {
		mavenProject.getModel().setParent(parentProject);
	}
	String disableWSO2Repo = preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
	                                                      DISABLE_WSO2_REPOSITORY, null, null);
	if (disableWSO2Repo == null) {
		MavenUtils.updateMavenRepo(mavenProject);
	}
	Repository globalRepositoryFromPreference = getGlobalRepositoryFromPreference();

	if (globalRepositoryFromPreference != null) {
		mavenProject.getModel().addRepository(globalRepositoryFromPreference);
		mavenProject.getModel().addPluginRepository(globalRepositoryFromPreference);
	}
	MavenUtils.saveMavenProject(mavenProject, pomLocation);
}
 
Example #23
Source File: AbstractWSO2ProjectCreationWizard.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public void createPOM(File pomLocation) throws Exception {
	MavenInfo mavenInfo = getModel().getMavenInfo();

	String customGroupId = preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
	                                                    GLOBAL_MAVEN_GROUP_ID, null, null);
	String customVersion = preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
	                                                    GLOBAL_MAVEN_VERSION, null, null);

	MavenProject mavenProject = MavenUtils.createMavenProject(customGroupId != null ? customGroupId
	                                                                               : mavenInfo.getGroupId(),
	                                                          mavenInfo.getArtifactId(),
	                                                          customVersion != null ? customVersion
	                                                                               : mavenInfo.getVersion(),
	                                                          mavenInfo.getPackageName());
	Parent parentProject = getModel().getMavenInfo().getParentProject();
	if (parentProject != null) {
		mavenProject.getModel().setParent(parentProject);
	}
	String disableWSO2Repo = preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui",
	                                                      DISABLE_WSO2_REPOSITORY, null, null);
	if (disableWSO2Repo == null) {
		MavenUtils.updateMavenRepo(mavenProject);
	}
	Repository globalRepositoryFromPreference = getGlobalRepositoryFromPreference();

	if (globalRepositoryFromPreference != null) {
		mavenProject.getModel().addRepository(globalRepositoryFromPreference);
		mavenProject.getModel().addPluginRepository(globalRepositoryFromPreference);
	}

	MavenUtils.saveMavenProject(mavenProject, pomLocation);
}
 
Example #24
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 #25
Source File: LocationAwareMavenXpp3Writer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void writeRepository(Repository repository, String tagName, XmlSerializer serializer)
        throws java.io.IOException {
    serializer.startTag(NAMESPACE, tagName);
    flush(serializer);
    StringBuffer b = b(serializer);
    int start = b.length();
    if (repository.getReleases() != null) {
        writeRepositoryPolicy((RepositoryPolicy) repository.getReleases(), "releases", serializer);
    }
    if (repository.getSnapshots() != null) {
        writeRepositoryPolicy((RepositoryPolicy) repository.getSnapshots(), "snapshots", serializer);
    }
    if (repository.getId() != null) {
        writeValue(serializer, "id", repository.getId(), repository);
    }
    if (repository.getName() != null) {
        writeValue(serializer, "name", repository.getName(), repository);
    }
    if (repository.getUrl() != null) {
        writeValue(serializer, "url", repository.getUrl(), repository);
    }
    if ((repository.getLayout() != null) && !repository.getLayout().equals("default")) {
        writeValue(serializer, "layout", repository.getLayout(), repository);
    }
    serializer.endTag(NAMESPACE, tagName).flush();
    logLocation(repository, "", start, b.length());
}
 
Example #26
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 #27
Source File: NBRepositoryModelResolver.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void addRepository(Repository repository, boolean replace) throws InvalidRepositoryException {
    RepositorySystem repositorySystem = embedder.lookupComponent(RepositorySystem.class);
    try {
        ArtifactRepository repo = repositorySystem.buildArtifactRepository(repository);
        if(replace) { 
            remoteRepositories.remove(repo);
        }
        remoteRepositories.add(repo);
        remoteRepositories = repositorySystem.getEffectiveRepositories( remoteRepositories );
    } catch (org.apache.maven.artifact.InvalidRepositoryException ex) {
        throw new InvalidRepositoryException(ex.toString(), repository, ex);
    }
}
 
Example #28
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 #29
Source File: RepositoryModelResolver.java    From repairnator with MIT License 5 votes vote down vote up
private void download(File localRepoFile) throws IOException {
    for (Repository repository1 : repositories) {
        String repository1Url = repository1.getUrl();
        if (repository1Url.endsWith("/")) {
            repository1Url = repository1Url.substring(0, repository1Url.length() - 1);
        }
        URL url = new URL(repository1Url
                + localRepoFile.getAbsolutePath().substring(this.localRepository.getAbsolutePath().length()));

        logger.debug("Downloading " + url);

        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(url)
                .build();

        Response response = client.newCall(request).execute();

        if (response.code() == 200) {
            localRepoFile.getParentFile().mkdirs();
            FileWriter out = new FileWriter(localRepoFile);
            out.write(response.body().string());
            out.flush();
            out.close();
            return;
        }
    }
}
 
Example #30
Source File: RepositoryModelResolver.java    From repairnator with MIT License 5 votes vote down vote up
@Override
public void addRepository(Repository repository, boolean b) throws InvalidRepositoryException {
    for (Repository existingRepository : repositories) {
        if (existingRepository.getId().equals(repository.getId()) && !b) {
            return;
        }
    }

    repositories.add(repository);
}