use of org.apache.archiva.maven2.model.Artifact in project assembly64fx by freabemania.
the class InstallationService method unpackDynamic.
private void unpackDynamic(File content, LocationAndInstallationStatus location, Artifact entry, ArtifactDelta delta) throws Exception {
CancelableTask cancelTask = CancelableTask.of();
LocalStorageUtil.createDir(pathService.getTmpDynFolder());
unzipService.extractZip(content, pathService.getTmpDynFolder(), entry);
if (cancelTask.isCancelled()) {
return;
}
File[] files = LocalStorageUtil.getSubdirOrFile(pathService.getTmpDynFolder(), entry.getFolder()).listFiles();
File base = LocalStorageUtil.getSubdirOrFile(location.getLocation(), entry.getPrefix() + "/" + entry.getFolder());
Optional<File> releaseLogFile = Arrays.stream(files).filter(item -> item.getName().equals("releaselog.json")).findFirst();
List<ReleaseInfo> releaseInfoList = null;
List<ReleaseInfo> matchedReleaseInfoList = new ArrayList<>();
if (releaseLogFile.isPresent()) {
releaseInfoList = Support.readList(ReleaseInfo.class, releaseLogFile.get()).stream().collect(Collectors.toList());
for (ReleaseInfo item : releaseInfoList) {
String p = item.getPath();
int start = p.indexOf("/", p.indexOf("/") + 1);
item.setPath(entry.getPrefix() + "/" + entry.getFolder() + "/" + p.substring(start + 1));
item.setStrippedPath(entry.getFolder() + "/" + p.substring(start + 1));
}
}
for (File f : files) {
if (f.isDirectory()) {
String dirname = f.getName().toUpperCase();
char firstChar = dirname.charAt(0);
boolean isDigit = Character.isDigit(firstChar);
boolean isAlpha = Character.isAlphabetic(firstChar);
String target = findDestination(firstChar, dirname, base);
if (target != null) {
File t = null;
if (isDigit) {
t = new File(base.getAbsolutePath() + "/0-9/" + target + "/" + f.getName());
} else if (isAlpha) {
t = new File(base.getAbsolutePath() + "/" + String.valueOf(firstChar) + "/" + target + "/" + f.getName());
} else {
t = new File(base.getAbsolutePath() + "/___MISC___/" + target + "/" + f.getName());
}
FileUtils.forceMkdir(t);
FileUtils.copyDirectory(f, t);
if (releaseInfoList != null) {
ReleaseInfo matchedReleaseInfo = null;
for (ReleaseInfo item : releaseInfoList) {
File[] subdirs = f.listFiles(File::isDirectory);
for (File dir : subdirs) {
if (dir.getPath().contains(item.getStrippedPath())) {
matchedReleaseInfo = item;
break;
}
}
}
if (matchedReleaseInfo != null) {
matchedReleaseInfo.setPath(t.getAbsolutePath().substring(base.getAbsolutePath().length() + 1));
matchedReleaseInfoList.add(matchedReleaseInfo);
}
}
ProgressControlWrapper.getInstance().setProgressLabel("Moved " + f.getName() + " to " + t.getAbsolutePath());
if (cancelTask.isCancelled()) {
break;
}
} else {
LOGGER.info("Unable to install " + dirname);
}
}
}
ProgressControlWrapper.getInstance().increaseProgress();
if (releaseLogFile.isPresent()) {
File t = new File(base.getAbsolutePath() + "/releaselog.json");
LOGGER.info("Flushing rebuildt releaselog.json to " + t.getAbsolutePath());
Support.flush(matchedReleaseInfoList, t);
}
}
use of org.apache.archiva.maven2.model.Artifact in project assembly64fx by freabemania.
the class Main method refreshTree.
public static void refreshTree() {
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
ProgressbarEnhanced progressBar = (ProgressbarEnhanced) GlobalRepoService.getInstance().get("pbar");
if (progressBar != null) {
topContainer.getChildren().remove(progressBar);
}
rootItemBase.getChildren().clear();
for (WorkLocation location : userService.getLocations()) {
List<Artifact> artifactsDb = artifactsService.getArtifactsDb();
Set<LatestInstalledItemInfo> lastestAdditions = null;
if (location.exists()) {
lastestAdditions = InstallationService.getInstance().resolveLatestInstalledByLocation(location.toLocationAndInstallation());
} else {
lastestAdditions = lastestAdditionsNotFound;
}
ImageView icon = new ImageView();
icon.setFitWidth(20);
icon.setFitHeight(20);
if (location.exists()) {
if (userService.isInstallationPrimary(location.getId())) {
icon.setImage(ImageResolveService.getInstance().getImage("image-root-primary.png"));
} else {
icon.setImage(ImageResolveService.getInstance().getImage("image-root.png"));
}
TreeItem<GuiLocation> rootItem = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION_ROOT).name(Support.removeEndingSlash(location.getPath())).build(), icon);
rootItem.setExpanded(localDbService.getBooleanLocalDBSetting(resolveInstallationExpandedKey(location.getId()), false));
rootItemBase.getChildren().add(rootItem);
TreeItem<GuiLocation> leaf = rootItem;
for (Artifact entry : artifactsDb) {
String node = entry.getPrefix();
if (node != null) {
String[] path = node.split("/");
String leafKey = "";
for (String pathItem : path) {
leafKey += pathItem + "/";
ImageView testIcon = new ImageView();
testIcon.setFitWidth(20);
testIcon.setFitHeight(20);
if (checkIfFolderNeedsUpdate(leafKey, location) && userService.isPremium()) {
testIcon.setImage(ImageResolveService.getInstance().getImage("image-folder-updateneeded.png"));
} else {
testIcon.setImage(ImageResolveService.getInstance().getImage("image-folder.png"));
}
Optional<TreeItem<GuiLocation>> categoryItem = leaf.getChildren().stream().filter(item -> item.getValue().getName() != null && item.getValue().getName().equals(pathItem)).findFirst();
if (!categoryItem.isPresent()) {
TreeItem<GuiLocation> depNode = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.LEAF).name(pathItem).leafKey(leafKey).build(), testIcon);
leaf.getChildren().add(depNode);
leaf = depNode;
} else {
leaf = categoryItem.get();
}
leaf.setExpanded(localDbService.getBooleanLocalDBSetting(resolveLeafInInstallationExpandedKey(leaf.getValue()), false));
}
// we're at thre position in the list now with the correct leaf
if (!localDbService.hasLocalDBSetting("exclude_" + location.getId() + "_" + entry.getName())) {
ImageView itemIcon = new ImageView();
itemIcon.setFitWidth(16);
itemIcon.setFitHeight(16);
if (entry.getCurrentInstallingId() != null && entry.getCurrentInstallingId().equals(location.getId())) {
if (entry.isMarkedForUpdate() && !entry.isUpdating()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-waiting.png"));
} else if (entry.isUpdating()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-install2.png"));
}
} else {
if (entry.getHero() && userService.isFreemium()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notavailable.png"));
} else if (entry.getType() == ArtifactType.LOCAL && !artifactsService.isPrivateDirAvailable()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notavailable.png"));
} else if (!artifactsService.isInstalled(location.toLocationAndInstallation(), entry)) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notinstalled2bw.png"));
} else if (artifactsService.needsUpdate(location.toLocationAndInstallation(), entry)) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-needsupdatebw.png"));
} else {
Optional<LatestInstalledItemInfo> findFirst = lastestAdditions.stream().filter(item -> item.getId().equals(entry.getName())).findFirst();
if (findFirst.isPresent() && userService.isPremium()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-updated-new.png"));
} else {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-updated2.png"));
}
}
}
TreeItem<GuiLocation> depNode = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION).artifact(entry).build(), itemIcon);
leaf.getChildren().add(depNode);
}
// reset
leaf = rootItem;
}
}
} else {
icon.setImage(ImageResolveService.getInstance().getImage("image-root-invalid.png"));
TreeItem<GuiLocation> rootItem = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION_ROOT).name(Support.removeEndingSlash(location.getPath())).build(), icon);
rootItemBase.getChildren().add(rootItem);
}
}
if (Scheduler.getInstance() != null && Scheduler.getInstance().isWorking() && ProgressControlWrapper.getInstance().isClosed()) {
int height = 25;
progressBar = new ProgressbarEnhanced();
progressBar.setMinWidth(300);
progressBar.setMinHeight(height);
progressBar.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent event) -> handleMouseClicked2(event));
topContainer.getChildren().add(1, progressBar);
GlobalRepoService.getInstance().put("pbar", progressBar);
tree.setMinHeight(topContainer.getHeight() - menuBar.getHeight() - height);
} else {
tree.setMinHeight(topContainer.getHeight() - menuBar.getHeight());
}
} catch (Exception e) {
LOGGER.error("Unable to refresh view", e);
GenericMessageDialogController.withErrorProps("Ooops", "Unable to refresh view").showAndWait();
}
}
});
}
use of org.apache.archiva.maven2.model.Artifact in project assembly64fx by freabemania.
the class Scheduler method cancel.
@Override
public void cancel() {
try {
workQueue.clear();
for (Artifact entry : artifactsService.getArtifactsDb()) {
entry.setMarkedForUpdate(false);
entry.setUpdating(false);
}
Support.refreshTree();
} catch (Exception e) {
LOGGER.error("Exception when cancelling", e);
}
}
use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.
the class DownloadMergedIndexTest method downloadMergedIndex.
@Test
public void downloadMergedIndex() throws Exception {
Path tmpIndexDir = Paths.get(System.getProperty("java.io.tmpdir"), "tmpIndex");
if (Files.exists(tmpIndexDir)) {
FileUtils.deleteDirectory(tmpIndexDir.toFile());
}
String id = Long.toString(System.currentTimeMillis());
ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
managedRepository.setIndexDirectory(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + id);
ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
if (managedRepositoriesService.getManagedRepository(id) != null) {
managedRepositoriesService.deleteManagedRepository(id, false);
}
getManagedRepositoriesService().addManagedRepository(managedRepository);
RepositoriesService repositoriesService = getRepositoriesService();
repositoriesService.scanRepositoryNow(id, true);
// wait a bit to ensure index is finished
int timeout = 20000;
while (timeout > 0 && repositoriesService.alreadyScanning(id)) {
Thread.sleep(500);
timeout -= 500;
}
RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
String repoGroupId = "test-group";
if (repositoryGroupService.getRepositoryGroup(repoGroupId) != null) {
repositoryGroupService.deleteRepositoryGroup(repoGroupId);
}
RepositoryGroup repositoryGroup = new RepositoryGroup();
repositoryGroup.setId(repoGroupId);
repositoryGroup.setRepositories(Arrays.asList(id));
repositoryGroupService.addRepositoryGroup(repositoryGroup);
// create a repo with a remote on the one with index
id = Long.toString(System.currentTimeMillis());
managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
managedRepository.setIndexDirectory(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + id);
if (managedRepositoriesService.getManagedRepository(id) != null) {
managedRepositoriesService.deleteManagedRepository(id, false);
}
getManagedRepositoriesService().addManagedRepository(managedRepository);
RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
remoteRepository.setId("all-merged");
remoteRepository.setName("all-merged");
remoteRepository.setDownloadRemoteIndex(true);
remoteRepository.setUrl("http://localhost:" + port + "/repository/test-group");
remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/repository/test-group/.index");
remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
remoteRepository.setPassword(FakeCreateAdminService.ADMIN_TEST_PWD);
if (getRemoteRepositoriesService().getRemoteRepository(remoteRepository.getId()) != null) {
getRemoteRepositoriesService().deleteRemoteRepository(remoteRepository.getId());
}
getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
ProxyConnectorService proxyConnectorService = getProxyConnectorService();
ProxyConnector proxyConnector = new ProxyConnector();
proxyConnector.setProxyId("foo-bar1");
proxyConnector.setSourceRepoId(id);
proxyConnector.setTargetRepoId("all-merged");
proxyConnectorService.addProxyConnector(proxyConnector);
repositoriesService.scheduleDownloadRemoteIndex("all-merged", true, true);
// wait a bit
timeout = 20000;
while (timeout > 0) {
Thread.sleep(500);
timeout -= 500;
}
SearchService searchService = getSearchService();
SearchRequest request = new SearchRequest();
request.setRepositories(Arrays.asList(id));
request.setGroupId("org.apache.felix");
List<Artifact> artifacts = searchService.searchArtifacts(request);
assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
}
use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.
the class DefaultRepositoriesService method removeProjectVersion.
@Override
public Boolean removeProjectVersion(String repositoryId, String namespace, String projectId, String version) throws ArchivaRestServiceException {
// if not a generic we can use the standard way to delete artifact
if (!VersionUtil.isGenericSnapshot(version)) {
Artifact artifact = new Artifact(namespace, projectId, version);
artifact.setRepositoryId(repositoryId);
artifact.setContext(repositoryId);
return deleteArtifact(artifact);
}
if (StringUtils.isEmpty(repositoryId)) {
throw new ArchivaRestServiceException("repositoryId cannot be null", 400, null);
}
if (!isAuthorizedToDeleteArtifacts(repositoryId)) {
throw new ArchivaRestServiceException("not authorized to delete artifacts", 403, null);
}
if (StringUtils.isEmpty(namespace)) {
throw new ArchivaRestServiceException("groupId cannot be null", 400, null);
}
if (StringUtils.isEmpty(projectId)) {
throw new ArchivaRestServiceException("artifactId cannot be null", 400, null);
}
if (StringUtils.isEmpty(version)) {
throw new ArchivaRestServiceException("version cannot be null", 400, null);
}
RepositorySession repositorySession = repositorySessionFactory.createSession();
try {
ManagedRepositoryContent repository = getManagedRepositoryContent(repositoryId);
VersionedReference ref = new VersionedReference();
ref.setArtifactId(projectId);
ref.setGroupId(namespace);
ref.setVersion(version);
repository.deleteVersion(ref);
/*
ProjectReference projectReference = new ProjectReference();
projectReference.setGroupId( namespace );
projectReference.setArtifactId( projectId );
repository.getVersions( )
*/
ArtifactReference artifactReference = new ArtifactReference();
artifactReference.setGroupId(namespace);
artifactReference.setArtifactId(projectId);
artifactReference.setVersion(version);
MetadataRepository metadataRepository = repositorySession.getRepository();
Set<ArtifactReference> related = repository.getRelatedArtifacts(artifactReference);
log.debug("related: {}", related);
for (ArtifactReference artifactRef : related) {
repository.deleteArtifact(artifactRef);
}
Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts(repositoryId, namespace, projectId, version);
for (ArtifactMetadata artifactMetadata : artifacts) {
metadataRepository.removeArtifact(artifactMetadata, version);
}
metadataRepository.removeProjectVersion(repositoryId, namespace, projectId, version);
} catch (MetadataRepositoryException e) {
throw new ArchivaRestServiceException("Repository exception: " + e.getMessage(), 500, e);
} catch (MetadataResolutionException e) {
throw new ArchivaRestServiceException("Repository exception: " + e.getMessage(), 500, e);
} catch (RepositoryException e) {
throw new ArchivaRestServiceException("Repository exception: " + e.getMessage(), 500, e);
} finally {
repositorySession.save();
repositorySession.close();
}
return Boolean.TRUE;
}
Aggregations