Search in sources :

Example 11 with JoinString

use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.

the class GitManager method commitModifiedFiles.

public GitManager commitModifiedFiles(final ChangeSummary changeSummary) throws GitSubsystemException {
    lockAnd((me) -> {
        Status status;
        try {
            status = git.status().call();
        } catch (NoWorkTreeException | GitAPIException e) {
            throw new GitSubsystemException("Failed to retrieve status of: %s. Reason: %s", e, rootDir, e.getMessage());
        }
        final Map<String, StageState> css = status.getConflictingStageState();
        if (!css.isEmpty()) {
            throw new GitSubsystemException("%s contains conflicts. Cannot auto-commit.\n  %s", rootDir, new JoinString("\n  ", css.entrySet()));
        }
        final Set<String> toAdd = new HashSet<>();
        final Set<String> modified = status.getModified();
        if (modified != null && !modified.isEmpty()) {
            toAdd.addAll(modified);
        }
        final Set<String> untracked = status.getUntracked();
        if (untracked != null && !untracked.isEmpty()) {
            toAdd.addAll(untracked);
        }
        final Set<String> untrackedFolders = status.getUntrackedFolders();
        if (untrackedFolders != null && !untrackedFolders.isEmpty()) {
            toAdd.addAll(untrackedFolders);
        //            for ( String folderPath : untrackedFolders )
        //            {
        //                File dir = new File( rootDir, folderPath );
        //                Files.walkFileTree( null, null )
        //            }
        }
        if (!toAdd.isEmpty()) {
            addAndCommitPaths(changeSummary, toAdd);
        }
        return me;
    });
    return this;
}
Also used : Status(org.eclipse.jgit.api.Status) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException) StageState(org.eclipse.jgit.lib.IndexDiff.StageState) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) HashSet(java.util.HashSet)

Example 12 with JoinString

use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.

the class ImpliedRepoMaintainer method processImpliedRepos.

private boolean processImpliedRepos(final ImpliedRepoMaintJob job) {
    final Set<StoreKey> processed = new HashSet<>();
    // implications. Reachable means they could be in nested groups.
    for (final ArtifactStore member : job.reachableMembers) {
        processed.add(member.getKey());
    }
    logger.debug("Preset processed-implications to reachable members:\n  {}", new JoinString("\n  ", processed));
    int lastLen = 0;
    boolean changed = false;
    job.added = new ArrayList<>();
    // As soon as we go an iteration without adding a new member, we've captured everything.
    do {
        lastLen = job.members.size();
        for (final ArtifactStore member : new ArrayList<>(job.members)) {
            logger.debug("Processing member: {} for implied repos within group: {}", member.getKey(), job.group.getKey());
            processed.add(member.getKey());
            List<StoreKey> implied;
            try {
                implied = metadataManager.getStoresImpliedBy(member);
            } catch (final ImpliedReposException e) {
                logger.error("Failed to retrieve implied-store metadata for: " + member.getKey(), e);
                continue;
            }
            if (implied == null || implied.isEmpty()) {
                continue;
            }
            implied.removeAll(processed);
            for (final StoreKey key : implied) {
                logger.debug("Found implied store: {} not already in group: {}", key, job.group.getKey());
                ArtifactStore impliedStore;
                try {
                    impliedStore = storeManager.getArtifactStore(key);
                } catch (final IndyDataException e) {
                    logger.error("Failed to retrieve store: " + key + " implied by: " + member.getKey(), e);
                    continue;
                }
                logger.info("Adding: {} to group: {} (implied by POMs in: {})", key, job.group.getKey(), member.getKey());
                processed.add(key);
                job.added.add(key);
                job.group.addConstituent(key);
                job.members.add(impliedStore);
                changed = true;
            }
        }
    } while (job.members.size() > lastLen);
    return changed;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 13 with JoinString

use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.

the class ImpliedRepositoryDetector method addImpliedRepositories.

private void addImpliedRepositories(final ImplicationsJob job) {
    job.implied = new ArrayList<>();
    logger.debug("Retrieving repository/pluginRepository declarations from:\n  {}", new JoinString("\n  ", job.pomView.getDocRefStack()));
    final List<List<RepositoryView>> repoLists = Arrays.asList(job.pomView.getNonProfileRepositories(), job.pomView.getAllPluginRepositories());
    final ImpliedRepositoryCreator creator = createRepoCreator();
    if (creator == null) {
        logger.error("Cannot proceed without a valid ImpliedRepositoryCreator instance. Aborting detection.");
        return;
    }
    for (final List<RepositoryView> repos : repoLists) {
        if (repos == null || repos.isEmpty()) {
            continue;
        }
        for (final RepositoryView repo : repos) {
            final ProjectVersionRef gav = job.pathInfo.getProjectId();
            try {
                if (config.isBlacklisted(repo.getUrl())) {
                    logger.debug("Discarding blacklisted repository: {}", repo);
                    continue;
                } else if (!config.isIncludeSnapshotRepos() && !repo.isReleasesEnabled()) {
                    logger.debug("Discarding snapshot repository: {}", repo);
                    continue;
                }
            } catch (final MalformedURLException e) {
                logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to check if repository is blacklisted.", repo.getUrl(), gav, job.transfer), e);
            }
            logger.debug("Detected POM-declared repository: {}", repo);
            RemoteRepository rr = null;
            try {
                rr = storeManager.query().packageType(MAVEN_PKG_KEY).getRemoteRepositoryByUrl(repo.getUrl());
            } catch (IndyDataException e) {
                logger.error(String.format("Cannot lookup remote repositories by URL: %s. Reason: %s", e.getMessage()), e);
            }
            if (rr == null) {
                logger.debug("Creating new RemoteRepository for: {}", repo);
                rr = creator.createFrom(gav, repo, LoggerFactory.getLogger(creator.getClass()));
                if (rr == null) {
                    logger.warn("ImpliedRepositoryCreator didn't create anything for repo: {}, specified in: {}. Skipping.", repo.getId(), gav);
                    continue;
                }
                rr.setMetadata(METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
                if (!remoteValidator.isValid(rr)) {
                    logger.warn("Implied repository to: {} is invalid! Repository created was: {}", repo.getUrl(), rr);
                    continue;
                }
                final String changelog = String.format("Adding remote repository: %s (url: %s, name: %s), which is implied by the POM: %s (at: %s/%s)", repo.getId(), repo.getUrl(), repo.getName(), gav, job.transfer.getLocation().getUri(), job.transfer.getPath());
                final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, changelog);
                try {
                    final boolean result = storeManager.storeArtifactStore(rr, summary, true, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_BY_POM_TRANSFER, job.transfer));
                    logger.debug("Stored new RemoteRepository: {}. (successful? {})", rr, result);
                    job.implied.add(rr);
                } catch (final IndyDataException e) {
                    logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to store new remote repository.", repo.getUrl(), gav, job.transfer), e);
                }
            } else {
                logger.debug("Found existing RemoteRepository: {}", rr);
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) RepositoryView(org.commonjava.maven.galley.maven.model.view.RepositoryView) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) ArrayList(java.util.ArrayList) List(java.util.List) ChangeSummary(org.commonjava.indy.audit.ChangeSummary)

Example 14 with JoinString

use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.

the class ImpliedRepositoryDetector method addImpliedMetadata.

private boolean addImpliedMetadata(final ImplicationsJob job) {
    try {
        logger.debug("Adding implied-repo metadata to: {} and {}", job.store, new JoinString(", ", job.implied));
        metadataManager.addImpliedMetadata(job.store, job.implied);
        return true;
    } catch (final ImpliedReposException e) {
        logger.error("Failed to store list of implied stores in: " + job.store.getKey(), e);
    }
    return false;
}
Also used : JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException)

Example 15 with JoinString

use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.

the class StoreAdminHandler method getAll.

@ApiOperation("Retrieve the definitions of all artifact stores of a given type on the system")
@ApiResponses({ @ApiResponse(code = 200, response = StoreListingDTO.class, message = "The store definitions") })
@GET
@Produces(ApplicationContent.application_json)
public Response getAll(@ApiParam("Filter only stores that support the package type (eg. maven, npm). NOTE: '_all' returns all.") @PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type) {
    final StoreType st = StoreType.get(type);
    Response response;
    try {
        final List<ArtifactStore> stores = adminController.getAllOfType(packageType, st);
        logger.info("Returning listing containing stores:\n\t{}", new JoinString("\n\t", stores));
        final StoreListingDTO<ArtifactStore> dto = new StoreListingDTO<>(stores);
        response = formatOkResponseWithJsonEntity(dto, objectMapper);
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) ApiResponse(io.swagger.annotations.ApiResponse) StoreListingDTO(org.commonjava.indy.model.core.dto.StoreListingDTO) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

JoinString (org.commonjava.maven.atlas.ident.util.JoinString)16 URI (java.net.URI)5 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)5 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)5 Location (org.commonjava.maven.galley.model.Location)5 Transfer (org.commonjava.maven.galley.model.Transfer)5 ArrayList (java.util.ArrayList)4 StoreKey (org.commonjava.indy.model.core.StoreKey)4 PluginView (org.commonjava.maven.galley.maven.model.view.PluginView)4 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 IndyDataException (org.commonjava.indy.data.IndyDataException)3 EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)3 ProjectRelationship (org.commonjava.maven.atlas.graph.rel.ProjectRelationship)3 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponse (io.swagger.annotations.ApiResponse)2 ApiResponses (io.swagger.annotations.ApiResponses)2 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2