Compare commits

...

1 Commits

Author SHA1 Message Date
wchen-talend
b712fae74b TUP-4043:Make it possible to download from talend nexus server with
other group id but not only org.talend.libraries
2016-01-28 19:14:21 +08:00
7 changed files with 115 additions and 94 deletions

View File

@@ -122,10 +122,10 @@ public class ModuleNeeded {
*
*/
public enum ELibraryInstallStatus {
UNKNOWN,
INSTALLED,
UNUSED,
NOT_INSTALLED;
UNKNOWN,
INSTALLED,
UNUSED,
NOT_INSTALLED;
}
/**
@@ -281,8 +281,8 @@ public class ModuleNeeded {
} else {
// compute the status of the lib.
// first use the Library manager service
ILibraryManagerService libManagerService = (ILibraryManagerService) GlobalServiceRegister.getDefault()
.getService(ILibraryManagerService.class);
ILibraryManagerService libManagerService = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(
ILibraryManagerService.class);
Set<String> existLibraries = libManagerService.list();
if (existLibraries.contains(getModuleName())) {
status = ELibraryInstallStatus.INSTALLED;

View File

@@ -28,7 +28,6 @@ import org.talend.core.GlobalServiceRegister;
import org.talend.core.ILibraryManagerService;
import org.talend.core.model.general.ModuleNeeded;
import org.talend.core.runtime.maven.MavenArtifact;
import org.talend.core.runtime.maven.MavenConstants;
import org.talend.core.runtime.maven.MavenUrlHelper;
import org.talend.librariesmanager.maven.ArtifactsDeployer;
import org.talend.librariesmanager.maven.ShareLibrareisHelper;
@@ -87,9 +86,8 @@ public class ShareLibsJob extends Job {
return null;
}
// only deploy libraries with group id org.talend.libraries
MavenArtifact parseMvnUrl = MavenUrlHelper.parseMvnUrl(module.getMavenUri());
if (parseMvnUrl == null || !MavenConstants.DEFAULT_LIB_GROUP_ID.equals(parseMvnUrl.getGroupId())) {
if (parseMvnUrl == null) {
continue;
}

View File

@@ -89,12 +89,14 @@ abstract public class DownloadModuleRunnable implements IRunnableWithProgress {
boolean accepted;
try {
// check license
boolean isLicenseAccepted = LibManagerUiPlugin.getDefault().getPreferenceStore()
.getBoolean(module.getLicenseType());
accepted = isLicenseAccepted;
if (!accepted) {
subMonitor.worked(1);
continue;
if (module.getLicenseType() != null) {
boolean isLicenseAccepted = LibManagerUiPlugin.getDefault().getPreferenceStore()
.getBoolean(module.getLicenseType());
accepted = isLicenseAccepted;
if (!accepted) {
subMonitor.worked(1);
continue;
}
}
NexusDownloadHelperWithProgress downloader = new NexusDownloadHelperWithProgress();
if (!module.getMavenUris().isEmpty()) {

View File

@@ -142,8 +142,7 @@ public class RemoteModulesHelper {
NexusServerBean nexusServer = manager.getLibrariesNexusServer();
List<MavenArtifact> searchResults = manager.search(nexusServer.getServer(), nexusServer.getUserName(),
nexusServer.getPassword(), nexusServer.getRepositoryId(), MavenConstants.DEFAULT_LIB_GROUP_ID,
jarsToCheck, null);
nexusServer.getPassword(), nexusServer.getRepositoryId(), null, jarsToCheck, null);
monitor.worked(10);
for (MavenArtifact artifact : searchResults) {
String artifactId = artifact.getArtifactId();
@@ -496,6 +495,23 @@ public class RemoteModulesHelper {
}
}
}
} else {
// add package if it is not in the configured uri
final String[] split = mvnUri.split(MavenUrlHelper.SEPERATOR);
if (split.length < 4) {
final MavenArtifact parseMvnUrl = MavenUrlHelper.parseMvnUrl(mvnUri);
String name = module.getModuleName();
String type = null;
if (name.lastIndexOf(".") != -1) {
type = name.substring(name.lastIndexOf(".") + 1, name.length());
}
if (type == null) {
type = parseMvnUrl.getType();
}
mvnUri = MavenUrlHelper.generateMvnUrl(parseMvnUrl.getGroupId(), parseMvnUrl.getArtifactId(),
parseMvnUrl.getVersion(), type, parseMvnUrl.getClassifier());
}
}
if (mvnUri != null) {
if (!contextMap.keySet().contains(mvnUri)) {

View File

@@ -113,7 +113,10 @@ public class NexusDownloader implements IDownloadHelper {
bos.flush();
bos.close();
if (bytesDownloaded == contentLength) {
String snapshotUri = MavenUrlHelper.generateSnapshotMavenUri(mavenUri);
String snapshotUri = mavenUri;
if (MavenConstants.DEFAULT_LIB_GROUP_ID.equals(parseMvnUrl.getGroupId())) {
snapshotUri = MavenUrlHelper.generateSnapshotMavenUri(mavenUri);
}
ArtifactsDeployer deployer = new ArtifactsDeployer();
deployer.deployToLocalMaven(destination.getAbsolutePath(), snapshotUri);
}

View File

@@ -25,4 +25,5 @@ modules.required=Required for using this component.
ModulesNeededProvider.Module.Exception=Needed module list do not contains this module
ShareLibsJob.message=Share libraries from maven to {0} server
ShareLibsJob.sharingLibraries=Sharing libraries : {0}
ShareLibsJob.sharingLibraries=Sharing libraries : {0}
ShareLibsJob.searchLibraries=Search libraries with group id : {0}

View File

@@ -14,6 +14,7 @@ package org.talend.librariesmanager.maven;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -113,9 +114,8 @@ public abstract class ShareLibrareisHelper {
}
} else {
// share to custom nexus
int searchLimit = 50;
setJobName(job, Messages.getString("ShareLibsJob.message", TYPE_NEXUS));
final List<MavenArtifact> searchResults = new ArrayList<MavenArtifact>();
TalendLibsServerManager instance = TalendLibsServerManager.getInstance();
NexusServerBean customServer = instance.getCustomNexusServer();
if (customServer != null) {
@@ -126,86 +126,87 @@ public abstract class ShareLibrareisHelper {
SubMonitor mainSubMonitor = SubMonitor.convert(monitor, filesToShare.size());
Iterator<ModuleNeeded> iterator = filesToShare.keySet().iterator();
Iterator<ModuleNeeded> searchIter = filesToShare.keySet().iterator();
int index = 0;
int limit = searchLimit;
int shareIndex = 0;
Map<String, Map<ModuleNeeded, MavenArtifact>> groupIdAndModule = new HashMap<String, Map<ModuleNeeded, MavenArtifact>>();
while (iterator.hasNext()) {
final ModuleNeeded next = iterator.next();
final String mavenUriSnapshot = next.getMavenUriSnapshot();
final MavenArtifact parseMvnUrl = MavenUrlHelper.parseMvnUrl(mavenUriSnapshot);
Map<ModuleNeeded, MavenArtifact> moduleAndArtifactMap = groupIdAndModule.get(parseMvnUrl
.getGroupId());
if (moduleAndArtifactMap == null) {
moduleAndArtifactMap = new HashMap<ModuleNeeded, MavenArtifact>();
groupIdAndModule.put(parseMvnUrl.getGroupId(), moduleAndArtifactMap);
}
moduleAndArtifactMap.put(next, parseMvnUrl);
}
Iterator<String> groupIdIter = groupIdAndModule.keySet().iterator();
while (groupIdIter.hasNext()) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
String jarsToCheck = "";
while (shareIndex < limit && index < limit && index < filesToShare.size()) {
ModuleNeeded toCheck = searchIter.next();
String jarName = toCheck.getModuleName();
String artifactId = jarName;
int lastIndexOf = jarName.lastIndexOf(".");
if (lastIndexOf != -1) {
artifactId = jarName.substring(0, lastIndexOf);
}
jarsToCheck += artifactId;
index++;
if (index < limit && index < filesToShare.size()) {
jarsToCheck += ",";
}
if (index == limit || index == filesToShare.size()) {
searchResults.clear();
// only talend offical nexus support search by multiple groupid seperated by ;
searchResults.addAll(instance.search(customServer.getServer(),
customServer.getUserName(), customServer.getPassword(),
customServer.getRepositoryId(), MavenConstants.DEFAULT_LIB_GROUP_ID, null, null));
}
final String groupIdToSearch = groupIdIter.next();
// only share jars with org.talend.libraries for now because the customer nexus must use
// SNAPSHOT for it , but other groups we do not deploy as SNAPSHOT
if (!MavenConstants.DEFAULT_LIB_GROUP_ID.equals(groupIdToSearch)) {
continue;
}
shareIndex++;
if (shareIndex == limit) {
limit += searchLimit;
// search by group id
mainSubMonitor.setTaskName(Messages.getString("ShareLibsJob.searchLibraries", groupIdToSearch));
final List<MavenArtifact> searchResults = instance.search(customServer.getServer(),
customServer.getUserName(), customServer.getPassword(), customServer.getRepositoryId(),
groupIdToSearch, null, null);
final Map<ModuleNeeded, MavenArtifact> moduleAndArtifactMap = groupIdAndModule
.get(groupIdToSearch);
final Iterator<ModuleNeeded> moduleIterator = moduleAndArtifactMap.keySet().iterator();
while (moduleIterator.hasNext()) {
ModuleNeeded next = moduleIterator.next();
File file = filesToShare.get(next);
String pomPath = file.getParent();
String name = file.getName();
MavenArtifact artifact = moduleAndArtifactMap.get(next);
boolean eixst = false;
for (MavenArtifact remoteAtifact : searchResults) {
String groupId = artifact.getGroupId();
String artifactId = artifact.getArtifactId();
String version = artifact.getVersion();
String rGroup = remoteAtifact.getGroupId();
String rArtifact = remoteAtifact.getArtifactId();
String rVersion = remoteAtifact.getVersion();
if (groupId != null && artifactId != null && version != null && groupId.equals(rGroup)
&& artifactId.equals(rArtifact) && version.equals(rVersion)) {
eixst = true;
break;
}
}
if (eixst) {
continue;
}
mainSubMonitor.setTaskName(Messages.getString("ShareLibsJob.sharingLibraries", name));
int indexOf = name.lastIndexOf(".");
if (indexOf != -1) {
pomPath = pomPath + "/" + name.substring(0, indexOf) + "." + MavenConstants.PACKAGING_POM;
}
try {
deployToLocalMaven(deployer, file, next);
deployer.installToRemote(file, artifact, artifact.getType());
File pomFile = new File(pomPath);
if (pomFile.exists()) {
deployer.installToRemote(pomFile, artifact, MavenConstants.PACKAGING_POM);
}
mainSubMonitor.worked(1);
} catch (Exception e) {
ExceptionHandler.process(new Exception("Share libraries :" + name + " failed !", e));
status = new Status(IStatus.ERROR, "unknown", IStatus.ERROR, "Share libraries :" + name
+ " failed !", e);
continue;
}
}
ModuleNeeded next = iterator.next();
File file = filesToShare.get(next);
String pomPath = file.getParent();
String name = file.getName();
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(next.getMavenUriSnapshot());
if (artifact == null) {
continue;
}
boolean eixst = false;
for (MavenArtifact remoteAtifact : searchResults) {
String groupId = artifact.getGroupId();
String artifactId = artifact.getArtifactId();
String version = artifact.getVersion();
String rGroup = remoteAtifact.getGroupId();
String rArtifact = remoteAtifact.getArtifactId();
String rVersion = remoteAtifact.getVersion();
if (groupId != null && artifactId != null && version != null && groupId.equals(rGroup)
&& artifactId.equals(rArtifact) && version.equals(rVersion)) {
eixst = true;
break;
}
}
if (eixst) {
continue;
}
mainSubMonitor.setTaskName(Messages.getString("ShareLibsJob.sharingLibraries", name));
int indexOf = name.lastIndexOf(".");
if (indexOf != -1) {
pomPath = pomPath + "/" + name.substring(0, indexOf) + "." + MavenConstants.PACKAGING_POM;
}
try {
deployToLocalMaven(deployer, file, next);
deployer.installToRemote(file, artifact, artifact.getType());
File pomFile = new File(pomPath);
if (pomFile.exists()) {
deployer.installToRemote(pomFile, artifact, MavenConstants.PACKAGING_POM);
}
mainSubMonitor.worked(1);
} catch (Exception e) {
ExceptionHandler.process(new Exception("Share libraries :" + name + " failed !", e));
status = new Status(IStatus.ERROR, "unknown", IStatus.ERROR, "Share libraries :" + name
+ " failed !", e);
continue;
}
}
}