Compare commits
1 Commits
cmeng/chor
...
bhe/bugfix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51f1f1ebd2 |
@@ -380,4 +380,14 @@ public class MavenUrlHelper {
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String getSNAPSHOTVersion(String rVersion) {
|
||||
if (rVersion == null) {
|
||||
return rVersion;
|
||||
}
|
||||
if (rVersion.contains("-")) {
|
||||
return rVersion.substring(0, rVersion.indexOf("-") + 1) + MavenUrlHelper.VERSION_SNAPSHOT;
|
||||
}
|
||||
return rVersion;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@@ -58,8 +57,6 @@ import org.talend.commons.ui.gmf.util.DisplayUtils;
|
||||
import org.talend.commons.ui.runtime.image.EImage;
|
||||
import org.talend.commons.ui.runtime.image.ImageProvider;
|
||||
import org.talend.commons.ui.swt.dialogs.IConfigModuleDialog;
|
||||
import org.talend.core.GlobalServiceRegister;
|
||||
import org.talend.core.ILibraryManagerService;
|
||||
import org.talend.core.model.general.ModuleNeeded;
|
||||
import org.talend.core.model.general.ModuleNeeded.ELibraryInstallStatus;
|
||||
import org.talend.core.model.general.ModuleToInstall;
|
||||
@@ -103,8 +100,6 @@ public class ConfigModuleDialog extends TitleAreaDialog implements IConfigModule
|
||||
|
||||
private Button useCustomBtn;
|
||||
|
||||
private boolean useCustom;
|
||||
|
||||
private String urlToUse;
|
||||
|
||||
private String defaultURI;
|
||||
@@ -537,15 +532,11 @@ public class ConfigModuleDialog extends TitleAreaDialog implements IConfigModule
|
||||
ret = ConfigModuleHelper.searchRemoteArtifacts(name);
|
||||
}
|
||||
String[] items = ConfigModuleHelper.toArray(ret);
|
||||
Map<String, MavenArtifact> data = new HashMap<String, MavenArtifact>();
|
||||
for (MavenArtifact art : ret) {
|
||||
data.put(art.getFileName(false), art);
|
||||
}
|
||||
searchResultCombo.setData(data);
|
||||
searchResultCombo.setData(ret);
|
||||
if (items.length > 0) {
|
||||
searchResultCombo.setItems(items);
|
||||
searchResultCombo.setText(searchResultCombo.getItem(0));
|
||||
resultField.setProposals(items);
|
||||
resultField.setProposals(ConfigModuleHelper.toArrayUnique(items));
|
||||
} else {
|
||||
searchResultCombo.setText("");
|
||||
searchResultCombo.setItems(new String[0]);
|
||||
@@ -608,7 +599,6 @@ public class ConfigModuleDialog extends TitleAreaDialog implements IConfigModule
|
||||
}
|
||||
String originalText = defaultUriTxt.getText().trim();
|
||||
String customURIWithType = MavenUrlHelper.addTypeForMavenUri(customUriText.getText(), moduleName);
|
||||
useCustom = useCustomBtn.getSelection();
|
||||
if (useCustomBtn.getSelection()) {
|
||||
// if use custom uri:validate custom uri + check deploy status
|
||||
String errorMessage = ModuleMavenURIUtils.validateCustomMvnURI(originalText, customURIWithType);
|
||||
@@ -700,6 +690,7 @@ public class ConfigModuleDialog extends TitleAreaDialog implements IConfigModule
|
||||
if (installRadioBtn.getSelection()) {
|
||||
File jarFile = new File(jarPathTxt.getText().trim());
|
||||
MavenArtifact art = MavenUrlHelper.parseMvnUrl(urlToUse);
|
||||
moduleName = art.getFileName();
|
||||
String sha1New = ConfigModuleHelper.getSHA1(jarFile);
|
||||
art.setSha1(sha1New);
|
||||
// resolve jar locally
|
||||
@@ -732,7 +723,7 @@ public class ConfigModuleDialog extends TitleAreaDialog implements IConfigModule
|
||||
List<MavenArtifact> remoteArtifacts = null;
|
||||
try {
|
||||
remoteArtifacts = ConfigModuleHelper.searchRemoteArtifacts(art.getGroupId(),
|
||||
art.getArtifactId(), art.getVersion());
|
||||
art.getArtifactId(), null);
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
@@ -771,8 +762,8 @@ public class ConfigModuleDialog extends TitleAreaDialog implements IConfigModule
|
||||
// check sha1
|
||||
String sha1Local = ConfigModuleHelper.getSHA1(localFile);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, MavenArtifact> data = (Map<String, MavenArtifact>) searchResultCombo.getData();
|
||||
MavenArtifact art = data.get(moduleName);
|
||||
List<MavenArtifact> data = (List<MavenArtifact>) searchResultCombo.getData();
|
||||
MavenArtifact art = data.get(this.searchResultCombo.getSelectionIndex());
|
||||
try {
|
||||
// for nexus2 only
|
||||
ConfigModuleHelper.resolveSha1(art);
|
||||
@@ -796,6 +787,7 @@ public class ConfigModuleDialog extends TitleAreaDialog implements IConfigModule
|
||||
DownloadModuleRunnableWithLicenseDialog downloadModuleRunnable = new DownloadModuleRunnableWithLicenseDialog(
|
||||
toInstall, getShell());
|
||||
runProgress(downloadModuleRunnable);
|
||||
this.updateIndex(defaultURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -837,9 +829,19 @@ public class ConfigModuleDialog extends TitleAreaDialog implements IConfigModule
|
||||
private void setupMavenURIforSearch() {
|
||||
if (validateInputFields()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, MavenArtifact> data = (Map<String, MavenArtifact>) searchResultCombo.getData();
|
||||
if (data != null && data.get(moduleName) != null) {
|
||||
MavenArtifact art = data.get(moduleName);
|
||||
List<MavenArtifact> data = (List<MavenArtifact>) searchResultCombo.getData();
|
||||
if (data != null && !data.isEmpty()) {
|
||||
if (this.searchResultCombo.getSelectionIndex() < 0) {
|
||||
int i = 0;
|
||||
for (MavenArtifact temp : data) {
|
||||
if (temp.getFileName().equals(this.searchResultCombo.getText())) {
|
||||
this.searchResultCombo.select(i);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
MavenArtifact art = data.get(this.searchResultCombo.getSelectionIndex());
|
||||
defaultURIValue = MavenUrlHelper.generateMvnUrl(art);
|
||||
defaultUriTxt.setText(defaultURIValue);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -35,6 +36,7 @@ import org.talend.core.nexus.TalendLibsServerManager;
|
||||
import org.talend.core.runtime.maven.MavenArtifact;
|
||||
import org.talend.core.runtime.maven.MavenUrlHelper;
|
||||
import org.talend.librariesmanager.model.ModulesNeededProvider;
|
||||
import org.talend.librariesmanager.nexus.utils.VersionUtil;
|
||||
import org.talend.librariesmanager.ui.LibManagerUiPlugin;
|
||||
|
||||
/*
|
||||
@@ -45,6 +47,16 @@ public class ConfigModuleHelper {
|
||||
|
||||
private static final String LOCAL_M2 = MavenPlugin.getMaven().getLocalRepositoryPath();
|
||||
|
||||
private static final Set<String> IGNORED_FILE_EXTS = new HashSet<String>();
|
||||
static {
|
||||
IGNORED_FILE_EXTS.add("repositories");
|
||||
IGNORED_FILE_EXTS.add("lastUpdated");
|
||||
IGNORED_FILE_EXTS.add("sha1");
|
||||
IGNORED_FILE_EXTS.add("md5");
|
||||
IGNORED_FILE_EXTS.add("pom");
|
||||
IGNORED_FILE_EXTS.add("xml");
|
||||
}
|
||||
|
||||
private ConfigModuleHelper() {
|
||||
|
||||
}
|
||||
@@ -54,7 +66,8 @@ public class ConfigModuleHelper {
|
||||
IRepositoryArtifactHandler customerRepHandler = RepositoryArtifactHandlerManager.getRepositoryHandler(customNexusServer);
|
||||
if (customerRepHandler != null) {
|
||||
List<MavenArtifact> ret = customerRepHandler.search(name, true);
|
||||
return ret;
|
||||
|
||||
return VersionUtil.filterSnapshotArtifacts(ret);
|
||||
}
|
||||
return new ArrayList<MavenArtifact>();
|
||||
}
|
||||
@@ -66,7 +79,19 @@ public class ConfigModuleHelper {
|
||||
|
||||
List<String> ret = new ArrayList<String>();
|
||||
for (MavenArtifact art : artifacts) {
|
||||
ret.add(art.getFileName(false));
|
||||
ret.add(art.getFileName());
|
||||
}
|
||||
return ret.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public static String[] toArrayUnique(String[] arr) {
|
||||
if (arr == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
Set<String> ret = new HashSet<String>();
|
||||
for (String art : arr) {
|
||||
ret.add(art);
|
||||
}
|
||||
return ret.toArray(new String[0]);
|
||||
}
|
||||
@@ -78,7 +103,8 @@ public class ConfigModuleHelper {
|
||||
search(name, m2Dir, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return VersionUtil.filterSnapshotArtifacts(ret);
|
||||
|
||||
}
|
||||
|
||||
private static void search(String name, File dir, List<MavenArtifact> ret) throws Exception {
|
||||
@@ -87,11 +113,16 @@ public class ConfigModuleHelper {
|
||||
if (f.isDirectory()) {
|
||||
search(name, f, ret);
|
||||
} else {
|
||||
if (f.isFile() && f.getName().endsWith(".jar")
|
||||
&& StringUtils.containsIgnoreCase(FilenameUtils.getBaseName(f.getName()), name)) {
|
||||
if (f.isFile() && StringUtils.containsIgnoreCase(FilenameUtils.getName(f.getName()), name)) {
|
||||
|
||||
String ext = FilenameUtils.getExtension(f.getName());
|
||||
if (IGNORED_FILE_EXTS.contains(ext)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String path = f.getPath().substring(LOCAL_M2.length() + 1, f.getPath().length());
|
||||
|
||||
MavenArtifact art = parse(path);
|
||||
MavenArtifact art = parse(path, ext);
|
||||
if (art != null) {
|
||||
ret.add(art);
|
||||
}
|
||||
@@ -100,7 +131,7 @@ public class ConfigModuleHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static MavenArtifact parse(String path) {
|
||||
public static MavenArtifact parse(String path, String ext) {
|
||||
MavenArtifact art = new MavenArtifact();
|
||||
if (path == null || StringUtils.isEmpty(path)) {
|
||||
return null;
|
||||
@@ -127,14 +158,19 @@ public class ConfigModuleHelper {
|
||||
art.setGroupId(sb.toString());
|
||||
art.setArtifactId(a);
|
||||
art.setVersion(v);
|
||||
art.setType("jar");
|
||||
art.setType(ext);
|
||||
|
||||
String baseName = FilenameUtils.getBaseName(fname);
|
||||
if (!baseName.contains(v)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int endIndex = a.length() + v.length() + 1;
|
||||
if (baseName.length() > endIndex + 1) {
|
||||
String classifier = baseName.substring(endIndex + 1, baseName.length());
|
||||
art.setClassifier(classifier);
|
||||
}
|
||||
|
||||
return art;
|
||||
}
|
||||
|
||||
@@ -185,7 +221,6 @@ public class ConfigModuleHelper {
|
||||
for (MavenArtifact art : artifacts) {
|
||||
if (StringUtils.equals(art.getGroupId(), artifact.getGroupId())
|
||||
&& StringUtils.equals(art.getArtifactId(), artifact.getArtifactId())
|
||||
&& StringUtils.equals(art.getVersion(), artifact.getVersion())
|
||||
&& StringUtils.equals(art.getClassifier(), artifact.getClassifier())
|
||||
&& StringUtils.equals(art.getType(), artifact.getType())
|
||||
&& StringUtils.equals(art.getSha1(), artifact.getSha1())) {
|
||||
@@ -199,19 +234,21 @@ public class ConfigModuleHelper {
|
||||
ArtifactRepositoryBean customNexusServer = TalendLibsServerManager.getInstance().getCustomNexusServer();
|
||||
IRepositoryArtifactHandler customerRepHandler = RepositoryArtifactHandlerManager.getRepositoryHandler(customNexusServer);
|
||||
if (customerRepHandler != null) {
|
||||
boolean fromSnapshot = false;
|
||||
if (v != null && v.endsWith(MavenUrlHelper.VERSION_SNAPSHOT)) {
|
||||
fromSnapshot = true;
|
||||
}
|
||||
List<MavenArtifact> ret = customerRepHandler.search(g, a, v, true, fromSnapshot);
|
||||
List<MavenArtifact> ret = customerRepHandler.search(g, a, v, true, true);
|
||||
|
||||
if (customNexusServer.getType() == ArtifactRepositoryBean.NexusType.NEXUS_2.name()) {
|
||||
// resolve sha1
|
||||
for (MavenArtifact art : ret) {
|
||||
String sha1 = customerRepHandler.resolveRemoteSha1(art, !fromSnapshot);
|
||||
String sha1 = customerRepHandler.resolveRemoteSha1(art, false);
|
||||
if (sha1 != null) {
|
||||
art.setSha1(sha1);
|
||||
}
|
||||
if (StringUtils.isEmpty(art.getSha1())) {
|
||||
sha1 = customerRepHandler.resolveRemoteSha1(art, true);
|
||||
if (sha1 != null) {
|
||||
art.setSha1(sha1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -16,7 +16,9 @@ import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -39,6 +41,13 @@ public abstract class AbsNexus3SearchHandler implements INexus3SearchHandler {
|
||||
private static Logger log = Logger.getLogger(AbsNexus3SearchHandler.class);
|
||||
protected ArtifactRepositoryBean serverBean;
|
||||
|
||||
private static final Set<String> IGNORED_TYPES = new HashSet<String>();
|
||||
static {
|
||||
IGNORED_TYPES.add("pom");
|
||||
IGNORED_TYPES.add("sha1");
|
||||
IGNORED_TYPES.add("md5");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@value}
|
||||
* <p>
|
||||
@@ -132,8 +141,10 @@ public abstract class AbsNexus3SearchHandler implements INexus3SearchHandler {
|
||||
artifact.setVersion(jsonObject.getString("version")); //$NON-NLS-1$
|
||||
JSONArray assertsArray = jsonObject.getJSONArray("assets"); //$NON-NLS-1$
|
||||
artifact.setType(getPackageType(assertsArray));
|
||||
fillCheckSumData(assertsArray, artifact);
|
||||
resultList.add(artifact);
|
||||
if (artifact.getType() != null) {
|
||||
fillCheckSumData(assertsArray, artifact);
|
||||
resultList.add(artifact);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,21 +157,16 @@ public abstract class AbsNexus3SearchHandler implements INexus3SearchHandler {
|
||||
for (int i = 0; i < assertsArray.size(); i++) {
|
||||
JSONObject jsonObject = assertsArray.getJSONObject(i);
|
||||
String path = jsonObject.getString("path"); //$NON-NLS-1$
|
||||
if (path != null && path.endsWith(".exe")) { //$NON-NLS-1$
|
||||
return "exe"; //$NON-NLS-1$
|
||||
int idx = path.lastIndexOf('.');
|
||||
if (idx > -1) {
|
||||
type = path.substring(idx + 1);
|
||||
}
|
||||
if (path != null && path.endsWith(".zip")) { //$NON-NLS-1$
|
||||
return "zip"; //$NON-NLS-1$
|
||||
}
|
||||
if (path != null && path.endsWith(".jar")) { //$NON-NLS-1$
|
||||
return "jar"; //$NON-NLS-1$
|
||||
}
|
||||
if (path != null && path.endsWith(".pom")) { //$NON-NLS-1$
|
||||
type = "pom"; //$NON-NLS-1$
|
||||
if (!IGNORED_TYPES.contains(type)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
return type;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void fillCheckSumData(JSONArray assertsArray, MavenArtifact artifact) {
|
||||
|
||||
@@ -12,6 +12,14 @@
|
||||
// ============================================================================
|
||||
package org.talend.librariesmanager.nexus.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.talend.core.runtime.maven.MavenArtifact;
|
||||
import org.talend.core.runtime.maven.MavenUrlHelper;
|
||||
|
||||
/**
|
||||
@@ -20,13 +28,60 @@ import org.talend.core.runtime.maven.MavenUrlHelper;
|
||||
public class VersionUtil {
|
||||
|
||||
public static String getSNAPSHOTVersion(String rVersion) {
|
||||
if(rVersion == null) {
|
||||
return rVersion;
|
||||
}
|
||||
if(rVersion.contains("-")) {
|
||||
return rVersion.substring(0, rVersion.indexOf("-") + 1) + MavenUrlHelper.VERSION_SNAPSHOT;
|
||||
}
|
||||
return rVersion;
|
||||
return MavenUrlHelper.getSNAPSHOTVersion(rVersion);
|
||||
}
|
||||
|
||||
public static List<MavenArtifact> filterSnapshotArtifacts(List<MavenArtifact> arts) {
|
||||
List<MavenArtifact> ret = new ArrayList<MavenArtifact>();
|
||||
if (arts == null || arts.isEmpty()) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
Map<String, List<MavenArtifact>> snapshotArtifacts = new HashMap<String, List<MavenArtifact>>();
|
||||
|
||||
for (MavenArtifact art : arts) {
|
||||
if (isSnapshot(art.getVersion())) {
|
||||
String v = art.getVersion().split("-")[0];
|
||||
String key = art.getGroupId() + ":" + art.getArtifactId() + ":" + v;
|
||||
if (art.getType() != null) {
|
||||
key = key + ":" + art.getType();
|
||||
}
|
||||
if (art.getClassifier() != null) {
|
||||
key = key + ":" + art.getClassifier();
|
||||
}
|
||||
List<MavenArtifact> groupArts = null;
|
||||
if (snapshotArtifacts.containsKey(key)) {
|
||||
groupArts = snapshotArtifacts.get(key);
|
||||
} else {
|
||||
groupArts = new ArrayList<MavenArtifact>();
|
||||
snapshotArtifacts.put(key, groupArts);
|
||||
}
|
||||
groupArts.add(art);
|
||||
} else {
|
||||
ret.add(art);
|
||||
}
|
||||
}
|
||||
|
||||
Set<Entry<String, List<MavenArtifact>>> entries = snapshotArtifacts.entrySet();
|
||||
for (Entry<String, List<MavenArtifact>> entry : entries) {
|
||||
if (!entry.getValue().isEmpty()) {
|
||||
MavenArtifact art = entry.getValue().get(0);
|
||||
if (art != null) {
|
||||
art.setVersion(MavenUrlHelper.getSNAPSHOTVersion(art.getVersion()));
|
||||
ret.add(art);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static boolean isSnapshot(String v) {
|
||||
if (v != null && (v.contains("-") || v.toUpperCase().endsWith(MavenUrlHelper.VERSION_SNAPSHOT))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user