Compare commits
6 Commits
vdrokov_fi
...
cmeng/chor
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ae1b236b4 | ||
|
|
11283d417f | ||
|
|
bdc8061ea8 | ||
|
|
e9abdf6fee | ||
|
|
87fe04566a | ||
|
|
2e30f29ca2 |
@@ -575,7 +575,7 @@ public class ContextUtils {
|
||||
return false;
|
||||
}
|
||||
// need check the raw value, because in sourceParam, it's raw
|
||||
if (!sourceParam.getValue().equals(targetParamType.getRawValue())) {
|
||||
if (!StringUtils.equals(sourceParam.getValue(), targetParamType.getRawValue())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1112,3 +1112,4 @@ public class ContextUtils {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,8 +113,6 @@ public enum EParameterFieldType {
|
||||
|
||||
GROUPING_CAMPAIGN_CHOOSER, // htyin added for DQ Matching components
|
||||
MULTI_PATTERN, // yyin added TDQ-13437
|
||||
SYNC_NEXUS_BUTTON,
|
||||
CHECK_NEXUS_BUTTON,
|
||||
PATTERN_PROPERTY, // yyin, added TDQ-13437
|
||||
|
||||
UNIFIED_COMPONENTS,
|
||||
|
||||
@@ -1003,7 +1003,9 @@ public final class ProcessUtils {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean isChildRouteProcess(IProcess process) {
|
||||
List n = process.getNodesOfType("tRouteInput");
|
||||
if (n!=null && n.size()!=0) {
|
||||
|
||||
@@ -320,24 +320,28 @@ public class RepositoryUpdateManagerHelper {
|
||||
|
||||
// all the jobs
|
||||
for (IRepositoryViewObject process : processRep) {
|
||||
Item item = process.getProperty().getItem();
|
||||
boolean found = false;
|
||||
for (IProcess2 open : openedProcessList) {
|
||||
if (open.getId().equals(item.getProperty().getId())) {
|
||||
found = true;
|
||||
try {
|
||||
Item item = process.getProperty().getItem();
|
||||
boolean found = false;
|
||||
for (IProcess2 open : openedProcessList) {
|
||||
if (open.getId().equals(item.getProperty().getId())) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
continue;
|
||||
}
|
||||
checkMonitorCanceled(parentMonitor);
|
||||
parentMonitor.subTask(RepositoryUpdateManager.getUpdateJobInfor(item.getProperty()));
|
||||
if (found) {
|
||||
continue;
|
||||
}
|
||||
checkMonitorCanceled(parentMonitor);
|
||||
parentMonitor.subTask(RepositoryUpdateManager.getUpdateJobInfor(item.getProperty()));
|
||||
|
||||
// List<UpdateResult> resultFromProcess = getResultFromProcess(process, types, onlySimpleShow);
|
||||
// List<UpdateResult> resultFromProcess = getResultFromProcess(process, types, onlySimpleShow);
|
||||
|
||||
List<UpdateResult> resultFromProcess = getUpdatesNeededFromItems(parentMonitor, item, types);
|
||||
if (resultFromProcess != null) {
|
||||
resultList.addAll(resultFromProcess);
|
||||
List<UpdateResult> resultFromProcess = getUpdatesNeededFromItems(parentMonitor, item, types);
|
||||
if (resultFromProcess != null) {
|
||||
resultList.addAll(resultFromProcess);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ExceptionHandler.process(ex);
|
||||
}
|
||||
parentMonitor.worked(1);
|
||||
}
|
||||
|
||||
@@ -36,8 +36,6 @@ import org.talend.core.model.process.IElement;
|
||||
import org.talend.core.model.process.IElementParameter;
|
||||
import org.talend.core.model.process.INode;
|
||||
import org.talend.core.model.process.IProcess2;
|
||||
import org.talend.core.runtime.maven.MavenArtifact;
|
||||
import org.talend.core.runtime.maven.MavenUrlHelper;
|
||||
import org.talend.core.ui.CoreUIPlugin;
|
||||
import org.talend.core.ui.process.IGEFProcess;
|
||||
import org.talend.core.ui.services.IDesignerCoreUIService;
|
||||
@@ -192,33 +190,16 @@ public class ModuleListCellEditor extends DialogCellEditor {
|
||||
}
|
||||
// enable to refresh component setting after change modules.
|
||||
IElement element = this.tableParam.getElement();
|
||||
boolean isNotCConfig = element.getElementParameter("COMPONENT_NAME") == null ?
|
||||
true : !"cConfig".equals(element.getElementParameter("COMPONENT_NAME").getValue());
|
||||
if (element != null && isNotCConfig) {
|
||||
if (element != null) {
|
||||
IElementParameter updateComponentsParam = element.getElementParameter("UPDATE_COMPONENTS"); //$NON-NLS-1$
|
||||
if (updateComponentsParam != null) {
|
||||
updateComponentsParam.setValue(Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
// cConfig
|
||||
if (!isNotCConfig) {
|
||||
if (newValue.startsWith(MavenUrlHelper.MVN_PROTOCOL)) {
|
||||
MavenArtifact art = MavenUrlHelper.parseMvnUrl(newValue);
|
||||
newValue = art.getFileName();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
executeCommand(new ModelChangeCommand(tableParam, param.getName(), newValue, index));
|
||||
|
||||
if (newVal != null) {
|
||||
executeCommand(new ModelChangeCommand(tableParam, "JAR_PATH", newVal, index));
|
||||
}
|
||||
if (nexusVersion != null) {
|
||||
executeCommand(new ModelChangeCommand(tableParam, "JAR_NEXUS_VERSION", nexusVersion, index));
|
||||
}
|
||||
|
||||
oldValue = newValue;
|
||||
if (getTableViewer() != null) {
|
||||
getTableViewer().refresh(true);
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.talend.core.model.utils.JavaResourcesHelper;
|
||||
import org.talend.core.runtime.maven.MavenArtifact;
|
||||
import org.talend.core.runtime.maven.MavenConstants;
|
||||
import org.talend.core.runtime.maven.MavenUrlHelper;
|
||||
import org.talend.core.runtime.process.LastGenerationInfo;
|
||||
import org.talend.core.runtime.process.TalendProcessArgumentConstant;
|
||||
import org.talend.core.runtime.projectsetting.IProjectSettingTemplateConstants;
|
||||
import org.talend.core.runtime.repository.build.IMavenPomCreator;
|
||||
@@ -52,6 +53,7 @@ import org.talend.core.ui.ITestContainerProviderService;
|
||||
import org.talend.designer.maven.model.TalendMavenConstants;
|
||||
import org.talend.designer.maven.template.ETalendMavenVariables;
|
||||
import org.talend.designer.maven.tools.ProcessorDependenciesManager;
|
||||
import org.talend.designer.maven.utils.JobUtils;
|
||||
import org.talend.designer.maven.utils.PomIdsHelper;
|
||||
import org.talend.designer.maven.utils.PomUtil;
|
||||
import org.talend.designer.runprocess.IBigDataProcessor;
|
||||
@@ -134,9 +136,16 @@ public abstract class AbstractMavenProcessorPom extends CreateMavenBundleTemplat
|
||||
|
||||
Map<ETalendMavenVariables, String> variablesValuesMap = new HashMap<ETalendMavenVariables, String>();
|
||||
// no need check property is null or not, because if null, will get default ids.
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobGroupId, PomIdsHelper.getJobGroupId(property));
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobArtifactId, PomIdsHelper.getJobArtifactId(property));
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobVersion, PomIdsHelper.getJobVersion(property));
|
||||
|
||||
if (JobUtils.isJob(property) && ProcessUtils.isChildRouteProcess(process)) {
|
||||
JobInfo lastMainJob = LastGenerationInfo.getInstance().getLastMainJob();
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobGroupId, PomIdsHelper.getJobGroupId(lastMainJob.getProcessor().getProperty()));
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobVersion, PomIdsHelper.getJobVersion(lastMainJob.getProcessor().getProperty()));
|
||||
}else {
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobGroupId, PomIdsHelper.getJobGroupId(property));
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobVersion, PomIdsHelper.getJobVersion(property));
|
||||
}
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobArtifactId, PomIdsHelper.getJobArtifactId(property));
|
||||
variablesValuesMap.put(ETalendMavenVariables.TalendJobVersion, property.getVersion());
|
||||
final String jobName = JavaResourcesHelper.escapeFileName(process.getName());
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobName, jobName);
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Set;
|
||||
|
||||
import org.talend.commons.exception.PersistenceException;
|
||||
import org.talend.core.GlobalServiceRegister;
|
||||
import org.talend.core.model.process.INode;
|
||||
import org.talend.core.model.process.IProcess;
|
||||
import org.talend.core.model.process.JobInfo;
|
||||
import org.talend.core.model.process.ProcessUtils;
|
||||
@@ -99,6 +100,13 @@ public class JobUtils {
|
||||
}
|
||||
return clonedJobInfos;
|
||||
}
|
||||
|
||||
public static boolean isRoute(Property p) {
|
||||
if (p != null) {
|
||||
return ERepositoryObjectType.getType(p).equals(ERepositoryObjectType.PROCESS_ROUTE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isJob(JobInfo job) {
|
||||
if (job != null && job.getProcessItem() != null) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
@@ -60,10 +61,25 @@ public class CustomUriManager {
|
||||
private final Object reloadingLock = new Object();
|
||||
|
||||
private CustomUriManager() {
|
||||
IFolder resourcePath = getResourcePath();
|
||||
try {
|
||||
customURIObject = loadResources(getResourcePath(), RepositoryConstants.PROJECT_SETTINGS_CUSTOM_URI_MAP);
|
||||
Assert.isNotNull(resourcePath);
|
||||
customURIObject = loadResources(resourcePath, RepositoryConstants.PROJECT_SETTINGS_CUSTOM_URI_MAP);
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
try {
|
||||
if (resourcePath != null) {
|
||||
customURIObject = loadResources(resourcePath.getLocation().toPortableString(),
|
||||
RepositoryConstants.PROJECT_SETTINGS_CUSTOM_URI_MAP);
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
ExceptionHandler.process(e1);
|
||||
|
||||
/**
|
||||
* Seems dangrous to load an empty json here, because it may overwrite the existing one
|
||||
*/
|
||||
// customURIObject = new JSONObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,10 +279,14 @@ public class CustomUriManager {
|
||||
|
||||
public void reloadCustomMapping() {
|
||||
try {
|
||||
if (isNeedReload) {
|
||||
if (isNeedReload || customURIObject == null) {
|
||||
synchronized (reloadingLock) {
|
||||
if (isNeedReload) {
|
||||
customURIObject.clear();
|
||||
if (isNeedReload || customURIObject == null) {
|
||||
if (customURIObject == null) {
|
||||
customURIObject = new JSONObject();
|
||||
} else {
|
||||
customURIObject.clear();
|
||||
}
|
||||
JSONObject loadResources = loadResources(getResourcePath(),
|
||||
RepositoryConstants.PROJECT_SETTINGS_CUSTOM_URI_MAP);
|
||||
customURIObject.putAll(loadResources);
|
||||
|
||||
@@ -8,5 +8,78 @@
|
||||
<relativePath>../../../</relativePath>
|
||||
</parent>
|
||||
<artifactId>org.talend.librariesmanager.test</artifactId>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
</project>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.talend.studio.test</groupId>
|
||||
<artifactId>nexus.upload.test.new</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>zip</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.studio.test</groupId>
|
||||
<artifactId>nexus.upload.test.new</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>dll</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.studio.test</groupId>
|
||||
<artifactId>nexus.upload.test.new</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>exe</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.studio.test</groupId>
|
||||
<artifactId>nexus.upload.test.new</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.studio.test</groupId>
|
||||
<artifactId>nexus.upload.test.old</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>zip</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.studio.test</groupId>
|
||||
<artifactId>nexus.upload.test.old</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>dll</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.studio.test</groupId>
|
||||
<artifactId>nexus.upload.test.old</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>exe</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.studio.test</groupId>
|
||||
<artifactId>nexus.upload.test.old</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>2.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includeGroupIds>org.talend.studio.test</includeGroupIds>
|
||||
<copyPom>true</copyPom>
|
||||
<includeArtifactIdIds>nexus.upload.test.old,nexus.upload.test.new</includeArtifactIdIds>
|
||||
<excludeTransitive>true</excludeTransitive>
|
||||
<outputDirectory>${project.basedir}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
rep.create.endpoint=/service/rest/v1/repositories/maven/hosted
|
||||
rep.list.endpoint=/service/rest/v1/repositories/maven/hosted/{repid}
|
||||
component.search.endpoint=/service/rest/v1/search
|
||||
component.delete.endpoint=/service/rest/v1/components/{id}
|
||||
component.upload.command=curl -v -u {user}:{password} -X POST \"{server}/service/rest/v1/components?repository={repid}\" -F maven2.groupId={groupid} -F maven2.artifactId={artifactid} -F maven2.version={version} -F maven2.asset1=@{filepath} -F maven2.asset1.extension={fileext}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "NEWREPNAME",
|
||||
"online": true,
|
||||
"storage": {
|
||||
"blobStoreName": "default",
|
||||
"strictContentTypeValidation": false,
|
||||
"writePolicy": "ALLOW"
|
||||
},
|
||||
"cleanup": {
|
||||
"policyNames": [
|
||||
"string"
|
||||
]
|
||||
},
|
||||
"maven": {
|
||||
"versionPolicy": "NEWVERSIONPOLICY",
|
||||
"layoutPolicy": "STRICT"
|
||||
}
|
||||
}
|
||||
@@ -12,17 +12,72 @@
|
||||
// ============================================================================
|
||||
package org.talend.librariesmanager.nexus;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.InvalidSyntaxException;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.service.cm.Configuration;
|
||||
import org.osgi.service.cm.ConfigurationAdmin;
|
||||
import org.talend.core.nexus.ArtifactRepositoryBean;
|
||||
import org.talend.core.nexus.IRepositoryArtifactHandler;
|
||||
import org.talend.core.nexus.NexusServerUtils;
|
||||
import org.talend.core.nexus.RepositoryArtifactHandlerManager;
|
||||
import org.talend.core.nexus.TalendMavenResolver;
|
||||
import org.talend.core.nexus.ArtifactRepositoryBean.NexusType;
|
||||
import org.talend.core.runtime.CoreRuntimePlugin;
|
||||
import org.talend.core.runtime.maven.MavenArtifact;
|
||||
import org.talend.core.runtime.maven.MavenUrlHelper;
|
||||
import org.talend.librariesmanager.model.service.LocalLibraryManager;
|
||||
import org.talend.librariesmanager.nexus.utils.NexusServerManagerProxy;
|
||||
import org.talend.librariesmanager.nexus.utils.RestAPIUtil;
|
||||
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
/**
|
||||
* created by wchen on Aug 18, 2017 Detailled comment
|
||||
*
|
||||
*/
|
||||
public class Nexus3RepositoryHandlerTest {
|
||||
|
||||
|
||||
private static Properties nexusprops = new Properties();
|
||||
private static ArtifactRepositoryBean customNexusServer;
|
||||
private static IRepositoryArtifactHandler repHandler;
|
||||
private static String[] types = new String[] {"jar", "pom", "exe", "zip", "dll"};
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws FileNotFoundException, IOException {
|
||||
URL entry = Platform.getBundle("org.talend.librariesmanager.test").getEntry("resources/nexus/nexus3.properties");
|
||||
nexusprops.load(new FileInputStream(FileLocator.toFileURL(entry).getFile()));
|
||||
customNexusServer = NexusServerManagerProxy.getInstance().getCustomNexusServer();
|
||||
repHandler = RepositoryArtifactHandlerManager.getRepositoryHandler(customNexusServer);
|
||||
createNexusRepository(customNexusServer.getRepositoryId(),"RELEASE");
|
||||
createNexusRepository(customNexusServer.getSnapshotRepId(),"SNAPSHOT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRepositoryURL() {
|
||||
ArtifactRepositoryBean serverBean = new ArtifactRepositoryBean();
|
||||
@@ -37,5 +92,329 @@ public class Nexus3RepositoryHandlerTest {
|
||||
String snapshotUrl = handler.getRepositoryURL(false);
|
||||
Assert.assertEquals("http://localhost:8081/repository/snapshot-repository/", snapshotUrl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckConnectionOK() {
|
||||
Assert.assertTrue(repHandler.checkConnection());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckConnectionFalse() {
|
||||
ArtifactRepositoryBean dummyNexusServer = NexusServerManagerProxy.getInstance().getDummyNexusServer();
|
||||
IRepositoryArtifactHandler repHandler = RepositoryArtifactHandlerManager.getRepositoryHandler(dummyNexusServer);
|
||||
Assert.assertFalse(repHandler.checkConnection());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeployOnSnapshot() throws Exception {
|
||||
for ( String type : types ) {
|
||||
String uri = "mvn:org.talend.libraries/test/6.0.0-SNAPSHOT/" + type;
|
||||
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
|
||||
try {
|
||||
clearLocalFile(uri);
|
||||
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
|
||||
URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0." + type);
|
||||
File originalJarFile = new File(FileLocator.toFileURL(entry).getFile());
|
||||
String originalSHA1 = getSha1(originalJarFile);
|
||||
// deploy the file to nexus
|
||||
repHandler.deploy(originalJarFile, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), type, artifact.getVersion());
|
||||
File reolved = repHandler.resolve(artifact);
|
||||
assertEquals(originalSHA1,getSha1(reolved));
|
||||
} finally {
|
||||
deleteNexusArtifact(artifact, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeployOnRelease() throws Exception {
|
||||
for ( String type : types ) {
|
||||
String uri = "mvn:org.talend.libraries/test/6.0.0/" + type ;
|
||||
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
|
||||
try {
|
||||
clearLocalFile(uri);
|
||||
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
|
||||
URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0." + type);
|
||||
File originalJarFile = new File(FileLocator.toFileURL(entry).getFile());
|
||||
String originalSHA1 = getSha1(originalJarFile);
|
||||
// deploy file to nexus
|
||||
repHandler.deploy(originalJarFile, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), type , artifact.getVersion());
|
||||
File resolved = repHandler.resolve(artifact);
|
||||
assertEquals(originalSHA1,getSha1(resolved));
|
||||
} finally {
|
||||
deleteNexusArtifact(artifact, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateOnSnapshot() throws Exception {
|
||||
for ( String type : types ) {
|
||||
String uri = "mvn:org.talend.libraries/test/6.0.0-SNAPSHOT/" + type ;
|
||||
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
|
||||
try {
|
||||
clearLocalFile(uri);
|
||||
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
|
||||
URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0." + type);
|
||||
File originalJarFile = new File(FileLocator.toFileURL(entry).getFile());
|
||||
entry = bundle.getEntry("/lib/nexus.upload.test.new-1.0.0." + type);
|
||||
File newJarFile = new File(FileLocator.toFileURL(entry).getFile());
|
||||
String originalSHA1 = getSha1(originalJarFile);
|
||||
String newJarSHA1 = getSha1(newJarFile);
|
||||
// deploy original jar without resolving
|
||||
repHandler.deploy(originalJarFile, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), type, artifact.getVersion());
|
||||
//deploy new jar
|
||||
repHandler.deploy(newJarFile, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), type, artifact.getVersion());
|
||||
//resolve and check the local file
|
||||
File resolved = repHandler.resolve(artifact);
|
||||
assertEquals(newJarSHA1,getSha1(resolved));
|
||||
} finally {
|
||||
deleteNexusArtifact(artifact, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveSha1NotExist() throws Exception {
|
||||
String uri = "mvn:org.talend.libraries/not-existing/6.0.0-SNAPSHOT/jar";
|
||||
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
|
||||
try {
|
||||
File f = repHandler.resolve(artifact);
|
||||
assertNull(f);
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
//It is one expected exception.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchOnRelease() throws Exception {
|
||||
for (String type: types) {
|
||||
String uri = "mvn:org.talend.libraries/test/6.0.0/" + type;
|
||||
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
|
||||
try {
|
||||
//Step1:Prepare the installed artifact
|
||||
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
|
||||
final URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0." + type);
|
||||
File fileToBeInstalled = new File(FileLocator.toFileURL(entry).getFile());
|
||||
//Step2:Search empty
|
||||
List<MavenArtifact> searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), true, false);
|
||||
if ( searchRet != null && searchRet.size() > 0 ) {
|
||||
Assert.fail("The artifact:" + uri + " is not expected to intalled before the test");
|
||||
}
|
||||
//Step3:Deploy the artifact
|
||||
repHandler.deploy(fileToBeInstalled, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType(), artifact.getVersion());
|
||||
//Step4:Verify the search result
|
||||
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), true, false);
|
||||
int i = 30;
|
||||
while ( searchRet.size() < 1 && i > 0 ) {
|
||||
Thread.sleep(1000);
|
||||
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), true, false);
|
||||
i--;
|
||||
}
|
||||
if (NexusServerUtils.IGNORED_TYPES.contains(type)) {
|
||||
assertEquals("Should get 0 artifact when searching for ignored type of " + uri , 0, searchRet.size());
|
||||
} else {
|
||||
assertEquals("Should get 1 artifact when searching for " + uri , 1, searchRet.size());
|
||||
assertEquals(artifact.getArtifactId(), searchRet.get(0).getArtifactId());
|
||||
assertEquals(artifact.getGroupId(), searchRet.get(0).getGroupId());
|
||||
assertEquals(artifact.getVersion(), searchRet.get(0).getVersion());
|
||||
assertEquals(artifact.getClassifier(), searchRet.get(0).getClassifier());
|
||||
assertEquals(artifact.getType(), searchRet.get(0).getType());
|
||||
}
|
||||
} finally {
|
||||
deleteNexusArtifact(artifact, true, true);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchOnSnapshot() throws Exception {
|
||||
String uri = "mvn:org.talend.libraries/test/6.0.0-SNAPSHOT/jar";
|
||||
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
|
||||
try {
|
||||
//Step1:Prepare the installed artifact
|
||||
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
|
||||
final URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0.jar");
|
||||
File fileToBeInstalled = new File(FileLocator.toFileURL(entry).getFile());
|
||||
//Step2:Search empty
|
||||
List<MavenArtifact> searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
|
||||
if ( searchRet != null && searchRet.size() > 0 ) {
|
||||
Assert.fail("The artifact is not expected to intalled before the test");
|
||||
}
|
||||
//Step3:Deploy the artifact
|
||||
repHandler.deploy(fileToBeInstalled, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "jar", artifact.getVersion());
|
||||
//Step4:Verify the search result
|
||||
//In snapshot repository, Timestamp is added in item version like 6.0.0-20201102.054042-1,
|
||||
//the search result for given version like 6.0.0 will be empty. Currently the version will not be given in search criteria.
|
||||
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
|
||||
int i = 30;
|
||||
while ( searchRet.size() < 1 && i > 0 ) {
|
||||
Thread.sleep(1000);
|
||||
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
|
||||
i--;
|
||||
}
|
||||
debug("testSearchSnapshot:" + searchRet);
|
||||
assertEquals(1, searchRet.size());
|
||||
assertEquals(artifact.getArtifactId(), searchRet.get(0).getArtifactId());
|
||||
assertEquals(artifact.getGroupId(), searchRet.get(0).getGroupId());
|
||||
//assertEquals(artifact.getVersion(), searchRet.get(0).getVersion());
|
||||
assertEquals(artifact.getClassifier(), searchRet.get(0).getClassifier());
|
||||
assertEquals(artifact.getType(), searchRet.get(0).getType());
|
||||
} finally {
|
||||
deleteNexusArtifact(artifact, false, true);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPaginationSearchOnSnapshot() throws Exception {
|
||||
//Pagination is enabled by Nexus when a search returns 50 results
|
||||
String uri = "mvn:org.talend.libraries/test/6.0.0-SNAPSHOT/zip";
|
||||
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
|
||||
List<MavenArtifact> searchRet = new ArrayList<MavenArtifact>();
|
||||
try {
|
||||
//Step1:Prepare the installed artifact
|
||||
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
|
||||
final URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0.zip");
|
||||
File fileToBeInstalled = new File(FileLocator.toFileURL(entry).getFile());
|
||||
//Step2:Deploy the artifacts for 101 times on snapshot repository .
|
||||
int i = 51;
|
||||
while ( i> 0 ) {
|
||||
repHandler.deploy(fileToBeInstalled, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "zip", artifact.getVersion());
|
||||
i--;
|
||||
}
|
||||
//Step3:Verify the search result. It will take some time for the deployment and wait for most 60 seconds
|
||||
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
|
||||
i = 6;
|
||||
while ( searchRet.size() < 51 && i > 0 ) {
|
||||
Thread.sleep(10000);
|
||||
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
|
||||
i--;
|
||||
}
|
||||
assertEquals(51, searchRet.size());
|
||||
} finally {
|
||||
deleteNexusArtifacts(searchRet, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void testUpdateMavenResolver() throws InvalidSyntaxException, IOException {
|
||||
Dictionary<String, String> props = new Hashtable<String, String>();
|
||||
props.put("org.ops4j.pax.url.mvn.socket.readTimeout", "59");
|
||||
props.put("org.ops4j.pax.url.mvn.socket.connectionTimeout", "119");
|
||||
repHandler.updateMavenResolver(TalendMavenResolver.TALEND_ARTIFACT_LIBRARIES_RESOLVER, props);
|
||||
|
||||
BundleContext context = CoreRuntimePlugin.getInstance().getBundle().getBundleContext();
|
||||
ServiceReference ca = context.getServiceReference(ConfigurationAdmin.class);
|
||||
debug("" + ca);
|
||||
ConfigurationAdmin configAdmin = (ConfigurationAdmin) context.getService(ca);
|
||||
if ( configAdmin == null ) {
|
||||
Configuration conf = configAdmin.getConfiguration("(service.pid=org.ops4j.pax.url.mvn)");
|
||||
assertEquals("59", conf.getProperties().get("org.ops4j.pax.url.mvn.socket.readTimeout"));
|
||||
assertEquals("119", conf.getProperties().get("org.ops4j.pax.url.mvn.socket.connectionTimeout"));
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
@After
|
||||
public void cleanup() {
|
||||
try {
|
||||
String uri = "mvn:org.talend.libraries/test/6.0.0-SNAPSHOT/jar";
|
||||
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
|
||||
List<MavenArtifact> searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
|
||||
deleteNexusArtifacts(searchRet,false,true);
|
||||
|
||||
uri = "mvn:org.talend.libraries/test/6.0.0/jar";
|
||||
artifact = MavenUrlHelper.parseMvnUrl(uri);
|
||||
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, true, false);
|
||||
deleteNexusArtifacts(searchRet,true,true);
|
||||
} catch ( Exception ex ) {
|
||||
}
|
||||
}
|
||||
|
||||
private void clearLocalFile(String uri) {
|
||||
LocalLibraryManager localLibraryManager = new LocalLibraryManager();
|
||||
String localJarPath = localLibraryManager.getJarPathFromMaven(uri);
|
||||
debug("localJarPath:" + localJarPath);
|
||||
// force to delete the file to have a valid test
|
||||
if (localJarPath != null) {
|
||||
org.talend.utils.io.FilesUtils.deleteFolder(new File(localJarPath).getParentFile().getParentFile(), true);
|
||||
}
|
||||
// file should not exist anymore
|
||||
assertNull(localLibraryManager.getJarPathFromMaven(uri));
|
||||
|
||||
}
|
||||
|
||||
private static void createNexusRepository(String repId,String versionPolicy) throws IOException {
|
||||
if (!"SNAPSHOT".equalsIgnoreCase(versionPolicy) && !"RELEASE".equalsIgnoreCase(versionPolicy)) {
|
||||
Assert.fail("Repository Version Policy must be SNAPSHOT OR RELEASE, but got " + versionPolicy);
|
||||
}
|
||||
String getstmt = customNexusServer.getServer() +
|
||||
nexusprops.getProperty("rep.list.endpoint").replace("{repid}", repId);
|
||||
try {
|
||||
String[] response = RestAPIUtil.doRequest(getstmt, "GET", customNexusServer.getUserName(), customNexusServer.getPassword(), null);
|
||||
if ( response[0].equals("200")) return;
|
||||
} catch (Exception ex ) {
|
||||
//Can not find and will create a new one
|
||||
debug("Can not find the repository named as " + repId + " and will create a new one :" + ex.getMessage());
|
||||
}
|
||||
String createstmt = customNexusServer.getServer() + nexusprops.getProperty("rep.create.endpoint");
|
||||
String jsonfilepath = FileLocator.toFileURL(Platform.getBundle("org.talend.librariesmanager.test").getEntry("resources/nexus/nexus3_create_rep.json")).getFile();
|
||||
String data = new String(Files.readAllBytes(new File(jsonfilepath).toPath())).replace("NEWREPNAME", repId).replace("NEWVERSIONPOLICY", versionPolicy.toUpperCase());
|
||||
try {
|
||||
String[] response = RestAPIUtil.doRequest(createstmt, "POST", customNexusServer.getUserName(), customNexusServer.getPassword(), data);
|
||||
if ( response[0].equals("201")) debug("Created the test repository successfully!");
|
||||
} catch (Exception ex ) {
|
||||
debug("Exception when create the repository of " + repId + ":" + ex );
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteNexusArtifacts( List<MavenArtifact> artifacts,boolean isRelease, boolean skiperror) throws Exception{
|
||||
if (artifacts == null) return;
|
||||
for (MavenArtifact artifact : artifacts) {
|
||||
deleteNexusArtifact(artifact,isRelease,skiperror);
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteNexusArtifact(MavenArtifact artifact, boolean fromRelease, boolean skiperror) throws Exception {
|
||||
try {
|
||||
StringBuffer searchstmt = new StringBuffer();
|
||||
searchstmt.append(customNexusServer.getServer())
|
||||
.append(nexusprops.getProperty("component.search.endpoint"))
|
||||
.append("?repository=").append( fromRelease ? customNexusServer.getRepositoryId() : customNexusServer.getSnapshotRepId())
|
||||
.append("&group=").append(artifact.getGroupId())
|
||||
.append("&name=").append(artifact.getArtifactId());
|
||||
if ( !artifact.getVersion().endsWith(MavenUrlHelper.VERSION_SNAPSHOT))
|
||||
searchstmt.append("&version=").append(artifact.getVersion());
|
||||
String[] resp = RestAPIUtil.doRequest(searchstmt.toString(), "GET", customNexusServer.getUserName(), customNexusServer.getPassword(), null);
|
||||
if ( !resp[0].equals("200")) return;
|
||||
JSONObject obj = JSONObject.fromObject(resp[1]);
|
||||
JSONArray items = obj.getJSONArray("items");
|
||||
if ( items.size() < 1) return;
|
||||
JSONObject item = (JSONObject) items.get(0);
|
||||
String componentid = item.getString("id");
|
||||
String deltestmt = customNexusServer.getServer() + nexusprops.getProperty("component.delete.endpoint").replace("{id}", componentid);
|
||||
RestAPIUtil.doRequest(deltestmt, "DELETE", customNexusServer.getUserName(), customNexusServer.getPassword(), null);
|
||||
} catch (Exception ex) {
|
||||
if (!skiperror) throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
private String getSha1(File file) throws IOException {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
String sha1 = DigestUtils.shaHex(fis);
|
||||
fis.close();
|
||||
return sha1;
|
||||
}
|
||||
|
||||
private String getSha1(String file) throws IOException {
|
||||
return getSha1(new File(file));
|
||||
}
|
||||
|
||||
private static void debug(String message) {
|
||||
System.out.println("[DEBUG]:" + message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.talend.librariesmanager.nexus.utils;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.talend.core.nexus.ArtifactRepositoryBean;
|
||||
import org.talend.core.nexus.IRepositoryArtifactHandler;
|
||||
import org.talend.core.nexus.RepositoryArtifactHandlerManager;
|
||||
|
||||
public class NexusServerManagerProxy {
|
||||
|
||||
private static String NEXUS_USER = "nexus.user";
|
||||
private static String NEXUS_PASSWORD = "nexus.password";
|
||||
private static String NEXUS_URL = "nexus.url";
|
||||
private static String NEXUS_LIB_REPO = "nexus.lib.repo";
|
||||
private static String NEXUS_LIB_SNAPSHOT_REPO = "nexus.lib.repo.snapshot";
|
||||
private static String DEFAULT_LIB_REPO = "rep-for-test-releases";
|
||||
private static String DEFAULT_LIB_SNAPSHOT_REPO = "rep-for-test-snapshots";
|
||||
private static String NEXUS_LIB_SERVER_TYPE = "nexus.lib.server.type";
|
||||
|
||||
private static Properties props;
|
||||
private static NexusServerManagerProxy manager = null;
|
||||
|
||||
public static synchronized NexusServerManagerProxy getInstance() {
|
||||
if (manager == null) {
|
||||
manager = new NexusServerManagerProxy();
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
public ArtifactRepositoryBean getCustomNexusServer() {
|
||||
String nexus_url = System.getProperty(NEXUS_URL);
|
||||
String nexus_user = System.getProperty(NEXUS_USER);
|
||||
String nexus_pass = System.getProperty(NEXUS_PASSWORD);
|
||||
String repositoryId = System.getProperty(NEXUS_LIB_REPO, DEFAULT_LIB_REPO);
|
||||
String snapshotRepId = System.getProperty(NEXUS_LIB_SNAPSHOT_REPO, DEFAULT_LIB_SNAPSHOT_REPO);
|
||||
String serverType = System.getProperty(NEXUS_LIB_SERVER_TYPE, "NEXUS_3");
|
||||
ArtifactRepositoryBean serverBean = new ArtifactRepositoryBean();
|
||||
serverBean.setServer(nexus_url);
|
||||
serverBean.setUserName(nexus_user);
|
||||
serverBean.setPassword(nexus_pass);
|
||||
serverBean.setRepositoryId(repositoryId);
|
||||
serverBean.setSnapshotRepId(snapshotRepId);
|
||||
serverBean.setType(serverType);
|
||||
return serverBean;
|
||||
}
|
||||
|
||||
public ArtifactRepositoryBean getDummyNexusServer() {
|
||||
ArtifactRepositoryBean serverBean = getCustomNexusServer();
|
||||
serverBean.setServer("http://localhost:0000");
|
||||
return serverBean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.talend.librariesmanager.nexus.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
public class RestAPIUtil {
|
||||
public static String[] doRequest(String uri, String httpmethod, String user, String password, String data)
|
||||
throws Exception {
|
||||
String[] ret = new String[2];
|
||||
StringBuffer response = new StringBuffer();
|
||||
URL url = new URL(uri);
|
||||
String auth = user + ":" + password;
|
||||
try {
|
||||
byte[] encodedAuth = Base64.getEncoder().encode((auth.getBytes(StandardCharsets.UTF_8)));
|
||||
String authHeaderValue = "Basic " + new String(encodedAuth);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestProperty("Authorization", authHeaderValue);
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("Accept", "application/json");
|
||||
conn.setRequestMethod(httpmethod);
|
||||
if (data != null) {
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
conn.connect();
|
||||
try (OutputStreamWriter streamWriter = new OutputStreamWriter(conn.getOutputStream());) {
|
||||
streamWriter.write(data);
|
||||
streamWriter.flush();
|
||||
}
|
||||
}
|
||||
int responsecode = conn.getResponseCode();
|
||||
debug(responsecode + " is returned for " + httpmethod + " on the endpoint:" + uri);
|
||||
ret[0] = Integer.toString(responsecode);
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"))) {
|
||||
String responseLine = null;
|
||||
while ((responseLine = br.readLine()) != null) {
|
||||
response.append(responseLine.trim());
|
||||
}
|
||||
}
|
||||
ret[1] = response.toString();
|
||||
conn.disconnect();
|
||||
} catch (Exception ex) {
|
||||
debug(ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static void debug(String message) {
|
||||
System.out.println("[DEBUG]:" + message);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user