Search in sources :

Example 41 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.

the class SearchServiceTest method searchWithSearchUnknwownRepoId.

@Test
public /**
 * ensure we don't return response for an unknown repo
 */
void searchWithSearchUnknwownRepoId() throws Exception {
    SearchService searchService = getSearchService(authorizationHeader);
    SearchRequest searchRequest = new SearchRequest();
    searchRequest.setBundleExportPackage("org.apache.karaf.features.command.completers");
    searchRequest.setRepositories(Arrays.asList("tototititata"));
    List<Artifact> artifacts = searchService.searchArtifacts(searchRequest);
    assertNotNull(artifacts);
    assertTrue(" not 0 results for Bundle ExportPackage org.apache.karaf.features.command.completers but " + artifacts.size() + ":" + artifacts, artifacts.size() == 0);
}
Also used : SearchRequest(org.apache.archiva.rest.api.model.SearchRequest) SearchService(org.apache.archiva.rest.api.services.SearchService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 42 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.

the class SearchServiceTest method quickSearchOnArtifactIdGuest.

/**
 * same search but with Guest user
 *
 * @throws Exception
 */
@Test
public void quickSearchOnArtifactIdGuest() throws Exception {
    SearchService searchService = getSearchService(null);
    // START SNIPPET: quick-search
    List<Artifact> artifacts = searchService.quickSearch("commons-logging");
    // return all artifacts with groupId OR artifactId OR version OR packaging OR className
    // NOTE : only artifacts with classifier empty are returned
    // END SNIPPET: quick-search
    assertNotNull(artifacts);
    assertTrue(" not 6 results for commons-logging search but " + artifacts.size() + ":" + artifacts, artifacts.size() == 6);
    log.info("artifacts for commons-logging size {} search {}", artifacts.size(), artifacts);
}
Also used : SearchService(org.apache.archiva.rest.api.services.SearchService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 43 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.

the class Maven2RepositoryStorage method applyServerSideRelocation.

@Override
public void applyServerSideRelocation(ManagedRepositoryContent managedRepository, ArtifactReference artifact) throws ProxyDownloadException {
    if ("pom".equals(artifact.getType())) {
        return;
    }
    // Build the artifact POM reference
    ArtifactReference pomReference = new ArtifactReference();
    pomReference.setGroupId(artifact.getGroupId());
    pomReference.setArtifactId(artifact.getArtifactId());
    pomReference.setVersion(artifact.getVersion());
    pomReference.setType("pom");
    RepositoryProxyConnectors connectors = applicationContext.getBean("repositoryProxyConnectors#default", RepositoryProxyConnectors.class);
    // Get the artifact POM from proxied repositories if needed
    connectors.fetchFromProxies(managedRepository, pomReference);
    // Open and read the POM from the managed repo
    Path pom = managedRepository.toFile(pomReference);
    if (!Files.exists(pom)) {
        return;
    }
    try {
        // MavenXpp3Reader leaves the file open, so we need to close it ourselves.
        Model model = null;
        try (Reader reader = Files.newBufferedReader(pom, Charset.defaultCharset())) {
            model = MAVEN_XPP_3_READER.read(reader);
        }
        DistributionManagement dist = model.getDistributionManagement();
        if (dist != null) {
            Relocation relocation = dist.getRelocation();
            if (relocation != null) {
                // artifact is relocated : update the repositoryPath
                if (relocation.getGroupId() != null) {
                    artifact.setGroupId(relocation.getGroupId());
                }
                if (relocation.getArtifactId() != null) {
                    artifact.setArtifactId(relocation.getArtifactId());
                }
                if (relocation.getVersion() != null) {
                    artifact.setVersion(relocation.getVersion());
                }
            }
        }
    } catch (IOException e) {
    // Unable to read POM : ignore.
    } catch (XmlPullParserException e) {
    // Invalid POM : ignore
    }
}
Also used : Path(java.nio.file.Path) Model(org.apache.maven.model.Model) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) MavenMetadataReader(org.apache.archiva.maven2.metadata.MavenMetadataReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) RepositoryProxyConnectors(org.apache.archiva.proxy.model.RepositoryProxyConnectors) IOException(java.io.IOException) DistributionManagement(org.apache.maven.model.DistributionManagement) ArtifactReference(org.apache.archiva.model.ArtifactReference) Relocation(org.apache.maven.model.Relocation)

Example 44 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project assembly64fx by freabemania.

the class Main method handleMouseClicked.

private static void handleMouseClicked(MouseEvent event) {
    tree.setContextMenu(null);
    TreeItem<GuiLocation> selectedItem = tree.getSelectionModel().getSelectedItem();
    if (selectedItem == null || selectedItem.getValue() == null) {
        return;
    }
    if (selectedItem.getValue().getType() == TYPE.ROOT) {
        final ContextMenu contextMenu = new ContextMenu();
        if (userService.getLocations().size() < MAX_INSTALLATIONS) {
            contextMenu.getItems().add(createMenuWithAction(null, "Add new location", Type.ADD_LOCATION, selectedItem.getValue()));
        }
        contextMenu.getItems().add(createMenuWithAction(null, "Locally synced directory", Type.ADD_PRIVATE_DIR, null));
        contextMenu.getItems().add(createMenuWithAction(null, "Install and update all", Type.INSTALL_AND_UPDATE_ALL_LOCATIONS, selectedItem.getValue()));
        contextMenu.getItems().add(createMenuWithAction(null, "Update all", Type.UPDATE_ALL_LOCATIONS, selectedItem.getValue()));
        contextMenu.getItems().add(createMenuWithAction(null, "Refresh view", Type.REFRESH_VIEW, selectedItem.getValue()));
        contextMenu.getItems().add(createMenuWithAction(null, "Reset all views", Type.RESET_ALL_VIEWS, selectedItem.getValue()));
        tree.setContextMenu(contextMenu);
        return;
    }
    if (selectedItem.getValue().getType() == TYPE.INSTALLATION_ROOT) {
        GuiLocation selectedInstallation = selectedItem.getValue();
        if (userService.isInstallationExisting(selectedInstallation.getId())) {
            if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
                final ContextMenu contextMenu = new ContextMenu();
                contextMenu.getItems().add(createMenuWithAction(null, "Update and install all", Type.INSTALLUPDATE_ALL, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Update all", Type.UPDATE_ALL, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Housekeep", Type.HOUSEKEEP, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Set as primary", Type.SET_AS_PRIMARY, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Reset view", Type.RESET_VIEW, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Open folder", Type.OPEN_LOCATION, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Remove location", Type.REMOVE_LOCATION, selectedInstallation));
                tree.setContextMenu(contextMenu);
            } else if (event.getClickCount() == 2) {
                String key = resolveInstallationExpandedKey(selectedInstallation.getId());
                if (localDbService.hasLocalDBSetting(key)) {
                    localDbService.addLocalBooleanDBSetting(key, !localDbService.getBooleanLocalDBSetting(key));
                } else {
                    localDbService.addLocalBooleanDBSetting(key, Boolean.FALSE);
                }
            }
        } else {
            final ContextMenu contextMenu = new ContextMenu();
            contextMenu.getItems().add(createMenuWithAction(null, "Remove location", Type.REMOVE_LOCATION, selectedInstallation));
            tree.setContextMenu(contextMenu);
        }
        return;
    }
    if (selectedItem.getValue().getType() == TYPE.LEAF) {
        if (event.getClickCount() == 2) {
            GuiLocation selectedInstallation = selectedItem.getValue();
            String key = resolveLeafInInstallationExpandedKey(selectedInstallation);
            if (localDbService.hasLocalDBSetting(key)) {
                localDbService.addLocalBooleanDBSetting(key, !localDbService.getBooleanLocalDBSetting(key));
            } else {
                localDbService.addLocalBooleanDBSetting(key, Boolean.FALSE);
            }
        } else if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
            ContextMenu contextMenu = getContextMenu();
            contextMenu.getItems().add(createMenuWithAction(null, "Open folder", Type.OPEN_LEAF_LOCATION, selectedItem.getValue()));
        }
        return;
    }
    if (selectedItem.getValue().getType() == TYPE.INSTALLATION) {
        if (event.getClickCount() == 2) {
            tree.getSelectionModel().clearSelection();
            GuiUtils.showDialog("searchMain.fxml", "Search assemblydb", selectedItem.getValue().getArtifact());
            return;
        } else {
            try {
                if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
                    if (tree.getContextMenu() == null) {
                        tree.setContextMenu(new ContextMenu());
                    }
                    ContextMenu contextMenu = tree.getContextMenu();
                    contextMenu.getItems().clear();
                    GuiLocation selectedInstallation = selectedItem.getValue();
                    List<ActionAndIdHolder> actions = new ArrayList<>();
                    Artifact clickedEntry = selectedInstallation.getArtifact();
                    boolean installed = artifactsService.isInstalled(userService.getLocation(selectedInstallation.getId()).toLocationAndInstallation(), clickedEntry);
                    if (!installed) {
                        actions.add(new ActionAndIdHolder(clickedEntry, Type.INSTALL, selectedInstallation));
                    } else if (artifactsService.needsUpdate(userService.getLocation(selectedInstallation.getId()).toLocationAndInstallation(), clickedEntry)) {
                        actions.add(new ActionAndIdHolder(clickedEntry, Type.UPDATE, selectedInstallation));
                    }
                    boolean containsInstall = actions.stream().filter(item -> item.getType() == Type.INSTALL).findFirst().isPresent();
                    boolean containsUpdate = actions.stream().filter(item -> item.getType() == Type.UPDATE).findFirst().isPresent();
                    if (Support.isRemoteArtifact(clickedEntry) || (Support.isLocalArtifact(clickedEntry) && artifactsService.isPrivateDirAvailable())) {
                        if (containsInstall) {
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Install", Type.INSTALL, selectedInstallation));
                        } else if (containsUpdate) {
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Update", Type.INSTALL, selectedInstallation));
                        }
                    }
                    contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Info", Type.INFO, selectedInstallation));
                    if (installed) {
                        contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Open folder", Type.OPEN, selectedInstallation));
                    }
                    if (Support.isRemoteArtifact(clickedEntry) && artifactsService.isPrivateDirAvailable()) {
                        if (!installed) {
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Hide", Type.HIDE, selectedInstallation));
                        } else {
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Uninstall", Type.UNINSTALL, selectedInstallation));
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Hide & uninstall", Type.HIDE, selectedInstallation));
                        }
                    }
                    if (Support.isRemoteArtifact(clickedEntry) && userService.isPremium()) {
                        contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Search", Type.SEARCH, selectedInstallation));
                    }
                    if (clickedEntry.isMarkedForUpdate()) {
                        if (!clickedEntry.isUpdating()) {
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Cancel", Type.CANCEL_UPDATE, selectedInstallation));
                        }
                    }
                    if (installed && Support.isRemoteArtifact(clickedEntry)) {
                        String baseLocation = Support.appendPathIfMissing(userService.getLocation(selectedInstallation.getId()).toLocationAndInstallation().getLocation()) + clickedEntry.getAbsoluteInstallationPath();
                        File releaseNoteFile = new File(Support.appendPathIfMissing(baseLocation + "/releaselog.json"));
                        ReturningTask<Void> showExtraMenuTask = () -> {
                            if (releaseNoteFile.exists()) {
                                Platform.runLater(() -> {
                                    contextMenu.getItems().add(createMenuWithAction(clickedEntry, "View new entries", Type.SHOW_RELEASES, selectedInstallation, baseLocation));
                                });
                            }
                            return null;
                        };
                        ExecutorUtil.executeAsyncWithRetry(showExtraMenuTask);
                    }
                } else {
                    tree.getSelectionModel().clearSelection();
                }
            } catch (Exception e) {
                LOGGER.error("Exception in mouseclick", e);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) GuiLocation(se.light.assembly64.model.GuiLocation) ContextMenu(javafx.scene.control.ContextMenu) Artifact(se.light.assembly64.model.Artifact) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 45 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project assembly64fx by freabemania.

the class ArtifactsService method getArtifactsDb.

public List<Artifact> getArtifactsDb(boolean refresh) {
    if (artifactsDb == null || refresh) {
        try {
            List<Artifact> tmp = getClient().target(getBackendServer()).path("/leet/artifacts2").request().header("email", getSessionInfo().getEmail()).header("token", getSessionInfo().getToken()).get(new GenericType<List<Artifact>>() {
            });
            if (localDbService.hasPrivateDirConfigured()) {
                String path = localDbService.getPrivateDir().replace("\\", "/");
                String name = path.substring(path.lastIndexOf("/") + 1);
                Artifact localArtifact = Artifact.localArtifact("Misc", name);
                tmp.add(localArtifact);
            }
            Collections.sort(tmp, (i1, i2) -> (i1.getPrefix() + i1.getFolder()).toLowerCase().compareTo((i2.getPrefix() + i2.getFolder()).toLowerCase()));
            artifactsDb = Collections.unmodifiableList(tmp);
        } catch (Exception e) {
            LOGGER.error("Unable to parse localdb", e);
            throw new RuntimeException(e);
        }
    }
    return artifactsDb;
}
Also used : List(java.util.List) Artifact(se.light.assembly64.model.Artifact) Support.isRemoteArtifact(se.light.assembly64.Support.isRemoteArtifact) IOException(java.io.IOException)

Aggregations

Artifact (org.apache.archiva.maven2.model.Artifact)37 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)14 SearchService (org.apache.archiva.rest.api.services.SearchService)14 BrowseService (org.apache.archiva.rest.api.services.BrowseService)11 Path (java.nio.file.Path)10 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)9 Artifact (se.light.assembly64.model.Artifact)9 List (java.util.List)8 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)8 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)8 File (java.io.File)7 IOException (java.io.IOException)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)6 Arrays (java.util.Arrays)5 HashSet (java.util.HashSet)5